Skip to content

Commit 35d0537

Browse files
committed
fix: properly indent html attribute when printed on multiline
__Input__ ```twig <iframe class="" src="https://www.google.com/maps/embed" frameborder="0" allowfullscreen></iframe> ``` __Output__ ```diff - <iframe class="" + <iframe + class="" src="https://www.google.com/maps/embed" frameborder="0" allowfullscreen></iframe> ```
1 parent 0f1ebaf commit 35d0537

File tree

13 files changed

+44
-12
lines changed

13 files changed

+44
-12
lines changed

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55
### Features
66
- Add support for [empty coalesce operator](https://plugins.craftcms.com/empty-coalesce), a CraftCMS extension
77

8+
### Bugfixes
9+
- Fix indentation for html attribute when printed on multiline. All attribute will be indented on each line.
10+
11+
__Input__
12+
```twig
13+
<iframe class=""
14+
src="https://www.google.com/maps/embed"
15+
frameborder="0"
16+
allowfullscreen></iframe>
17+
```
18+
19+
__Output__
20+
```twig
21+
- <iframe class=""
22+
+ <iframe
23+
+ class=""
24+
src="https://www.google.com/maps/embed"
25+
frameborder="0"
26+
allowfullscreen></iframe>
27+
```
28+
829
### Internals
930
- Remove unused dependencies `resolve`
1031

src/print/Element.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const printOpeningTag = (node, path, print) => {
1616
const hasAttributes = node.attributes && node.attributes.length > 0;
1717

1818
if (hasAttributes) {
19-
return [opener, indent([" ", printedAttributes]), openingTagEnd];
19+
return [opener, indent([line, printedAttributes]), openingTagEnd];
2020
}
2121
return [opener, openingTagEnd];
2222
};

tests/ControlStructures/__snapshots__/forInclude.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% for foo in range(1, category) %}
2-
<span key="{{ foo }}"
2+
<span
3+
key="{{ foo }}"
34
class="qtp-item__star icon-ic icon-icn_star--white {{ foo }}">
45
{% include './Star.twig' only %}
56
</span>

tests/ControlStructures/__snapshots__/if.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
</div>
88

99
{% if partner -%}
10-
<img class="{{ {
10+
<img
11+
class="{{ {
1112
(css.logo): not useWiderItems,
1213
(css.logoWider): useWiderItems
1314
}|classes }}"

tests/Element/__snapshots__/attributes.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<a href="#abcd" target="_blank" lang="en">Link</a>
22

3-
<fantasy {{ {
3+
<fantasy
4+
{{ {
45
id: accommodation.id.id,
56
ref: intersectionObserver|default,
67
class: 'hotel-item item-order__list-item js_co_item',

tests/Element/__snapshots__/manyAttributes.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<span attr1="one"
1+
<span
2+
attr1="one"
23
attr2="two"
34
attr3="three"
45
attr4="four"

tests/Element/__snapshots__/selfClosing.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<input type="text" name="user" />
22

3-
<input attr1="one"
3+
<input
4+
attr1="one"
45
attr2="two"
56
attr3="three"
67
attr4="four"

tests/Expressions/__snapshots__/mappingExpression.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151

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

54-
<div {{
54+
<div
55+
{{
5556
attributes.defaults({
5657
class: cva({
5758
base: 'alert shadow-md',

tests/Expressions/__snapshots__/objectExpression.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
}
88
}}
99

10-
<h1 class="{{ {
10+
<h1
11+
class="{{ {
1112
('hero__title--' ~ (locale|lower)): locale in ['CN', 'JP', 'DE', 'RU']
1213
}|classes }}">
1314
Heading

tests/Failing/__snapshots__/controversial.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
{% set isRewardRate = isMarriottRewardRate or (rewardRateAltIds and deal.dealId in altIds) %}
88

99
<!-- Always break objects -->
10-
<section class="{{ {
10+
<section
11+
class="{{ {
1112
base: css.prices
1213
} | classes }}"></section>
1314

tests/Failing/__snapshots__/failing.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
{# Inserts a newline where it shouldn't #}
3939
<span class="rat-chart__bar">
4040
<span class="rat-chart__bar-holder">
41-
<span class="rat-chart__bar-content rat-color--{{ valueIndex }}"
41+
<span
42+
class="rat-chart__bar-content rat-color--{{ valueIndex }}"
4243
{{ {
4344
style: width
4445
} | attrs }}>

tests/Statements/__snapshots__/macro.snap.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
sky,
1414
hedgehog)
1515
%}
16-
<input type="{{ type }}"
16+
<input
17+
type="{{ type }}"
1718
name="{{ name }}"
1819
value="{{ value|e }}"
1920
size="{{ size }}" />

tests/smoke-test.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<meta name="viewport"
5+
<meta
6+
name="viewport"
67
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
78
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
89
<title>

0 commit comments

Comments
 (0)