mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-15 00:23:10 +00:00
fixed #75, added test
This commit is contained in:
parent
b2b26e9ee1
commit
507dae9b50
4 changed files with 23 additions and 2 deletions
|
|
@ -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 "
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
3
tests/config_blank_lines_after_tag/html_six.html
Normal file
3
tests/config_blank_lines_after_tag/html_six.html
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{% block include %}
|
||||
{# {% include 'common/sticky-topbar-hidden-nav.html' %}#}
|
||||
{% endblock %}
|
||||
|
|
@ -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"])
|
||||
|
|
|
|||
Loading…
Reference in a new issue