fix(white space): prevent duplicate blank lines from being added

closes #297.
This commit is contained in:
Christopher Pickering 2022-07-25 07:55:30 -05:00
parent 0bebf846d3
commit 67306b4cd1
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
3 changed files with 16 additions and 2 deletions

View file

@ -94,7 +94,7 @@ def condense_html(html: str, config: Config) -> str:
for tag in [x.strip() for x in config.blank_line_after_tag.split(",")]:
html = re.sub(
re.compile(
rf"((?:{{%\s*?{tag}\b[^}}]+?%}}\n?)+)",
rf"((?:{{%\s*?{tag}\b[^}}]+?%}}\n?)+)(?=[^\n])",
re.IGNORECASE | re.MULTILINE | re.DOTALL,
),
func,

View file

@ -0,0 +1,3 @@
{% extends nothing %}
<div></div>

View file

@ -2,7 +2,7 @@
run::
pytest tests/test_config.py --cov=src/djlint --cov-branch \
pytest tests/test_config/test_blank_lines_after_tag/test_config.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
for a single test, run::
@ -94,3 +94,14 @@ def test_blank_lines_after_tag(runner: CliRunner) -> None:
["tests/test_config/test_blank_lines_after_tag/html_seven.html", "--check"],
)
assert result.exit_code == 0
# check that multiple blank lines are not added
result = runner.invoke(
djlint,
[
"tests/test_config/test_blank_lines_after_tag/html_eight.html",
"--preserve-blank-lines",
"--check",
],
)
assert result.exit_code == 0