Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Fix html attribute indentation when printed on multiline #100

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading