From fd332a60e19144af48bbd909c81c640e4f7e5003 Mon Sep 17 00:00:00 2001 From: davidodenwald Date: Sun, 14 May 2023 11:26:48 +0200 Subject: [PATCH] fix indentation after empty lines --- src/printer.ts | 6 +++--- test/cases/newline_between/expected.html | 16 ++++++++++++++++ test/cases/newline_between/input.html | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/printer.ts b/src/printer.ts index 2e8a1f4..5ec8d3f 100644 --- a/src/printer.ts +++ b/src/printer.ts @@ -44,7 +44,7 @@ const printExpression = (node: Expression): builders.Doc => { ); return node.preNewLines > 1 - ? builders.group([builders.hardline, builders.trim, expression]) + ? builders.group([builders.trim, builders.hardline, expression]) : expression; }; @@ -79,7 +79,7 @@ const printCommentBlock = (node: Node): builders.Doc => { }); return node.preNewLines > 1 - ? builders.group([builders.hardline, builders.trim, comment]) + ? builders.group([builders.trim, builders.hardline, comment]) : comment; }; @@ -162,7 +162,7 @@ export const embed: Printer["embed"] = ( const block = buildBlock(path, print, node as Block, mapped); return node.preNewLines > 1 - ? builders.group([builders.hardline, builders.trim, block]) + ? builders.group([builders.trim, builders.hardline, block]) : block; } return [...mapped, builders.hardline]; diff --git a/test/cases/newline_between/expected.html b/test/cases/newline_between/expected.html index ff17c82..fb87c1c 100644 --- a/test/cases/newline_between/expected.html +++ b/test/cases/newline_between/expected.html @@ -28,3 +28,19 @@ {% else %}
  • no users found
  • {% endfor %} + +{% macro input(name, value='', type='text', size=20) %} + + {{ my_variable|default('my_variable is not defined') }} + + {% for city, items in users|groupby("city") %} +
  • + {{ city }} +
      + {% for user in items %} +
    • {{ user.name }}
    • + {% endfor %} +
    +
  • + {% endfor %} +{% endmacro %} diff --git a/test/cases/newline_between/input.html b/test/cases/newline_between/input.html index 2704213..10d3f64 100644 --- a/test/cases/newline_between/input.html +++ b/test/cases/newline_between/input.html @@ -37,3 +37,17 @@
  • no users found
  • {% endfor %} + +{% macro input(name, value='', type='text', size=20) %} + +{{ my_variable|default('my_variable is not defined') }} + +{% for city, items in users|groupby("city") %} +
  • {{ city }} +
      {% for user in items %} +
    • {{ user.name }} +{% endfor %}
    +
  • +{% endfor %} + +{% endmacro %} \ No newline at end of file