Skip to content

Commit

Permalink
Preserve blank lines: fix bug with trailing space/tab. Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-vanderheijden committed Mar 18, 2024
1 parent 0a53b47 commit 701c70c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/djlint/formatter/condense.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def strip_space(config: Config, html: str, match: re.Match) -> str:
trailing_contents = r"\n \t"

if config.preserve_blank_lines:
line_contents = r"([^\n]+?)"
line_contents = r"([^\n]*)"
trailing_contents = r" \t"

if not config.preserve_leading_space:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_config/test_preserve_blank_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,14 @@
({"preserve_blank_lines": True}),
id="whitespace test",
),
pytest.param(
("<div>\n\t\n\t<div>\n\t\n\t</div>\n\t\n</div>"),
("<div>\n\n <div></div>\n\n</div>\n"),
({"preserve_blank_lines": True}),
id="whitespace test with tabs",
),
]


@pytest.mark.parametrize(("source", "expected", "args"), test_data)
def test_base(source, expected, args):
output = formatter(config_builder(args), source)
Expand Down

0 comments on commit 701c70c

Please sign in to comment.