From 35d0537653ec35dcf37367f73c795e207f438131 Mon Sep 17 00:00:00 2001 From: zackad Date: Sun, 8 Dec 2024 09:52:10 +0700 Subject: [PATCH] fix: properly indent html attribute when printed on multiline __Input__ ```twig ``` __Output__ ```diff - ``` --- CHANGELOG.md | 21 +++++++++++++++++++ src/print/Element.js | 2 +- .../__snapshots__/forInclude.snap.twig | 3 ++- .../__snapshots__/if.snap.twig | 3 ++- .../__snapshots__/attributes.snap.twig | 3 ++- .../__snapshots__/manyAttributes.snap.twig | 3 ++- .../__snapshots__/selfClosing.snap.twig | 3 ++- .../__snapshots__/mappingExpression.snap.twig | 3 ++- .../__snapshots__/objectExpression.snap.twig | 3 ++- .../__snapshots__/controversial.snap.twig | 3 ++- tests/Failing/__snapshots__/failing.snap.twig | 3 ++- .../Statements/__snapshots__/macro.snap.twig | 3 ++- tests/smoke-test.twig | 3 ++- 13 files changed, 44 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cba32e8a..8a312707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + +``` + +__Output__ +```twig +- +``` + ### Internals - Remove unused dependencies `resolve` diff --git a/src/print/Element.js b/src/print/Element.js index 87fa0e64..94f90ce2 100644 --- a/src/print/Element.js +++ b/src/print/Element.js @@ -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]; }; diff --git a/tests/ControlStructures/__snapshots__/forInclude.snap.twig b/tests/ControlStructures/__snapshots__/forInclude.snap.twig index b28f0edc..80bc11f2 100644 --- a/tests/ControlStructures/__snapshots__/forInclude.snap.twig +++ b/tests/ControlStructures/__snapshots__/forInclude.snap.twig @@ -1,5 +1,6 @@ {% for foo in range(1, category) %} - {% include './Star.twig' only %} diff --git a/tests/ControlStructures/__snapshots__/if.snap.twig b/tests/ControlStructures/__snapshots__/if.snap.twig index c9130f78..16c0576d 100644 --- a/tests/ControlStructures/__snapshots__/if.snap.twig +++ b/tests/ControlStructures/__snapshots__/if.snap.twig @@ -7,7 +7,8 @@ {% if partner -%} - Link - - Heading diff --git a/tests/Failing/__snapshots__/controversial.snap.twig b/tests/Failing/__snapshots__/controversial.snap.twig index d1d4c0a0..cbc005f3 100644 --- a/tests/Failing/__snapshots__/controversial.snap.twig +++ b/tests/Failing/__snapshots__/controversial.snap.twig @@ -7,7 +7,8 @@ {% set isRewardRate = isMarriottRewardRate or (rewardRateAltIds and deal.dealId in altIds) %} -
diff --git a/tests/Failing/__snapshots__/failing.snap.twig b/tests/Failing/__snapshots__/failing.snap.twig index 35e38d10..27bb6099 100644 --- a/tests/Failing/__snapshots__/failing.snap.twig +++ b/tests/Failing/__snapshots__/failing.snap.twig @@ -38,7 +38,8 @@ {# Inserts a newline where it shouldn't #} - diff --git a/tests/Statements/__snapshots__/macro.snap.twig b/tests/Statements/__snapshots__/macro.snap.twig index e01f3a3e..ff1d2643 100644 --- a/tests/Statements/__snapshots__/macro.snap.twig +++ b/tests/Statements/__snapshots__/macro.snap.twig @@ -13,7 +13,8 @@ sky, hedgehog) %} - diff --git a/tests/smoke-test.twig b/tests/smoke-test.twig index 6aadbe66..1a5531f4 100644 --- a/tests/smoke-test.twig +++ b/tests/smoke-test.twig @@ -2,7 +2,8 @@ -