fixed #75, added test

This commit is contained in:
Christopher Pickering 2021-11-16 11:49:25 +01:00
parent b2b26e9ee1
commit 507dae9b50
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
4 changed files with 23 additions and 2 deletions

View file

@ -63,3 +63,6 @@ quiet = true
[tool.pylint.messages_control]
disable = "E1120, R0914, E0401, R0912, R0916, R0913, W0104, R0801, W1404, R0902, R0903, R1732, R0915, C0301, R1702"
[tool.djlint]
blank_line_after_tag = "load, extends, include "

View file

@ -52,7 +52,14 @@ def condense_html(html: str, config: Config) -> str:
return match.group()
func = partial(condense_line, config)
def add_blank_line(config: Config, html: str, match: re.Match) -> str:
"""Add break after if not in ignored block."""
if inside_ignored_block(config, html, match):
return match.group()
return match.group() + "\n"
func = partial(add_blank_line, config, html)
# should we add blank lines after load tags?
if config.blank_line_after_tag:
@ -62,10 +69,12 @@ def condense_html(html: str, config: Config) -> str:
fr"((?:{{%\s*?{tag}[^}}]+?%}}\n?)+)",
re.IGNORECASE | re.MULTILINE | re.DOTALL,
),
r"\1\n",
func,
html,
)
func = partial(condense_line, config)
# put short single line tags on one line
html = re.sub(
re.compile(

View file

@ -0,0 +1,3 @@
{% block include %}
{# {% include 'common/sticky-topbar-hidden-nav.html' %}#}
{% endblock %}

View file

@ -147,6 +147,12 @@ def test_blank_lines_after_tag(runner: CliRunner) -> None:
)
assert result.exit_code == 0
# something perfect should stay perfect :)
result = runner.invoke(
djlint, ["tests/config_blank_lines_after_tag/html_six.html", "--check"]
)
assert result.exit_code == 0
def test_profile(runner: CliRunner) -> None:
result = runner.invoke(djlint, ["tests/config_profile/html.html"])