Skip to content

Commit

Permalink
fix: properly indent html attribute when printed on multiline
Browse files Browse the repository at this point in the history
__Input__
```twig
<iframe class=""
        src="https://www.google.com/maps/embed"
        frameborder="0"
        allowfullscreen></iframe>
```

__Output__
```twig
- <iframe class=""
+ <iframe
+     class=""
      src="https://www.google.com/maps/embed"
      frameborder="0"
      allowfullscreen></iframe>
```
  • Loading branch information
zackad committed Dec 8, 2024
1 parent 39607a4 commit 44beb8d
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 12 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
### Features
- Add support for [empty coalesce operator](https://plugins.craftcms.com/empty-coalesce), a CraftCMS extension

### Bugfixes
- Fix indentation for html attribute when printed on multiline. All attribute will be indented on each line.

__Input__
```twig
<iframe class=""
src="https://www.google.com/maps/embed"
frameborder="0"
allowfullscreen></iframe>
```

__Output__
```twig
- <iframe class=""
+ <iframe
+ class=""
src="https://www.google.com/maps/embed"
frameborder="0"
allowfullscreen></iframe>
```

### Internals
- Remove unused dependencies `resolve`

Expand Down
2 changes: 1 addition & 1 deletion src/print/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const printOpeningTag = (node, path, print) => {
const hasAttributes = node.attributes && node.attributes.length > 0;

if (hasAttributes) {
return [opener, indent([" ", printedAttributes]), openingTagEnd];
return [opener, indent([line, printedAttributes]), openingTagEnd];
}
return [opener, openingTagEnd];
};
Expand Down
3 changes: 2 additions & 1 deletion tests/ControlStructures/__snapshots__/forInclude.snap.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% for foo in range(1, category) %}
<span key="{{ foo }}"
<span
key="{{ foo }}"
class="qtp-item__star icon-ic icon-icn_star--white {{ foo }}">
{% include './Star.twig' only %}
</span>
Expand Down
3 changes: 2 additions & 1 deletion tests/ControlStructures/__snapshots__/if.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</div>

{% if partner -%}
<img class="{{ {
<img
class="{{ {
(css.logo): not useWiderItems,
(css.logoWider): useWiderItems
}|classes }}"
Expand Down
3 changes: 2 additions & 1 deletion tests/Element/__snapshots__/attributes.snap.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<a href="#abcd" target="_blank" lang="en">Link</a>

<fantasy {{ {
<fantasy
{{ {
id: accommodation.id.id,
ref: intersectionObserver|default,
class: 'hotel-item item-order__list-item js_co_item',
Expand Down
3 changes: 2 additions & 1 deletion tests/Element/__snapshots__/manyAttributes.snap.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<span attr1="one"
<span
attr1="one"
attr2="two"
attr3="three"
attr4="four"
Expand Down
3 changes: 2 additions & 1 deletion tests/Element/__snapshots__/selfClosing.snap.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<input type="text" name="user" />

<input attr1="one"
<input
attr1="one"
attr2="two"
attr3="three"
attr4="four"
Expand Down
3 changes: 2 additions & 1 deletion tests/Expressions/__snapshots__/mappingExpression.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@

{% props theme = null, text = null %}

<div {{
<div
{{
attributes.defaults({
class: cva({
base: 'alert shadow-md',
Expand Down
3 changes: 2 additions & 1 deletion tests/Expressions/__snapshots__/objectExpression.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
}
}}

<h1 class="{{ {
<h1
class="{{ {
('hero__title--' ~ (locale|lower)): locale in ['CN', 'JP', 'DE', 'RU']
}|classes }}">
Heading
Expand Down
3 changes: 2 additions & 1 deletion tests/Failing/__snapshots__/controversial.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
{% set isRewardRate = isMarriottRewardRate or (rewardRateAltIds and deal.dealId in altIds) %}

<!-- Always break objects -->
<section class="{{ {
<section
class="{{ {
base: css.prices
} | classes }}"></section>

Expand Down
3 changes: 2 additions & 1 deletion tests/Failing/__snapshots__/failing.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
{# Inserts a newline where it shouldn't #}
<span class="rat-chart__bar">
<span class="rat-chart__bar-holder">
<span class="rat-chart__bar-content rat-color--{{ valueIndex }}"
<span
class="rat-chart__bar-content rat-color--{{ valueIndex }}"
{{ {
style: width
} | attrs }}>
Expand Down
3 changes: 2 additions & 1 deletion tests/Statements/__snapshots__/macro.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
sky,
hedgehog)
%}
<input type="{{ type }}"
<input
type="{{ type }}"
name="{{ name }}"
value="{{ value|e }}"
size="{{ size }}" />
Expand Down
3 changes: 2 additions & 1 deletion tests/smoke-test.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport"
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>
Expand Down

0 comments on commit 44beb8d

Please sign in to comment.