Skip to content

Commit

Permalink
fix(white space): prevent duplicate blank lines from being added
Browse files Browse the repository at this point in the history
closes #297.
  • Loading branch information
Christopher Pickering committed Jul 25, 2022
1 parent 0bebf84 commit 67306b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/djlint/formatter/condense.py
Expand Up @@ -94,7 +94,7 @@ def add_blank_line(config: Config, html: str, match: re.Match) -> 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,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_config/test_blank_lines_after_tag/html_eight.html
@@ -0,0 +1,3 @@
{% extends nothing %}

<div></div>
13 changes: 12 additions & 1 deletion tests/test_config/test_blank_lines_after_tag/test_config.py
Expand Up @@ -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::
Expand Down Expand Up @@ -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

0 comments on commit 67306b4

Please sign in to comment.