From 92872bc53c7ede47584009b2285b4bed39849be1 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 1 Oct 2021 11:51:53 +0200 Subject: [PATCH] fixed #35 --- docs/conf.py | 2 +- docs/djlint/changelog.rst | 4 ++++ pyproject.toml | 2 +- src/djlint/formatter/indent_html.py | 6 ++++-- tests/config_blank_lines_after_tag/html_three.html | 5 +++++ tests/test_config.py | 11 ++++++++++- 6 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 tests/config_blank_lines_after_tag/html_three.html diff --git a/docs/conf.py b/docs/conf.py index ed722be..610c211 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,7 +12,7 @@ project = "djlint" copyright = "2021, Riverside Healthcare" author = "Christopher Pickering" -release = "0.4.8" +release = "0.4.9" version = release # -- General configuration --------------------------------------------------- diff --git a/docs/djlint/changelog.rst b/docs/djlint/changelog.rst index db348b4..ffe0934 100644 --- a/docs/djlint/changelog.rst +++ b/docs/djlint/changelog.rst @@ -1,6 +1,10 @@ Changelog ========= +0.4.9 +----- +- Fixed bug `#35 `_ + 0.4.8 ----- - Fixed bug `#34 `_ diff --git a/pyproject.toml b/pyproject.toml index 7ebd3b5..1213568 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name="djlint" -version="0.4.8" +version="0.4.9" description="HTML Template Linter and Formatter" license="GPL-3.0-or-later" authors=["Christopher Pickering "] diff --git a/src/djlint/formatter/indent_html.py b/src/djlint/formatter/indent_html.py index 004b323..1ea8725 100644 --- a/src/djlint/formatter/indent_html.py +++ b/src/djlint/formatter/indent_html.py @@ -174,10 +174,12 @@ def indent_html(rawcode: str, config: Config) -> str: if config.blank_line_after_tag: for tag in [x.strip() for x in config.blank_line_after_tag.split(",")]: beautified_code = re.sub( - fr"((?:{{%\s*?{tag}[^}}]+?%}}\n?)+)", + re.compile( + fr"((?:^{{%\s*?{tag}[^}}]+?%}}\n?)+)", + re.IGNORECASE | re.MULTILINE | re.DOTALL, + ), r"\1\n", beautified_code, - re.IGNORECASE, ) return beautified_code.strip() + "\n" diff --git a/tests/config_blank_lines_after_tag/html_three.html b/tests/config_blank_lines_after_tag/html_three.html new file mode 100644 index 0000000..1fad98a --- /dev/null +++ b/tests/config_blank_lines_after_tag/html_three.html @@ -0,0 +1,5 @@ +
+
+
{% include "pages/task/details_source.html.j2" %}
+
+
diff --git a/tests/test_config.py b/tests/test_config.py index 1756cc4..448ad4b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -7,7 +7,7 @@ run:: for a single test, run:: - pytest tests/test_config.py::test_profile --cov=src/djlint \ + pytest tests/test_config.py::test_blank_lines_after_tag --cov=src/djlint \ --cov-branch --cov-report xml:coverage.xml --cov-report term-missing """ @@ -91,6 +91,7 @@ def test_blank_lines_after_tag(runner: CliRunner) -> None: result = runner.invoke( djlint, ["tests/config_blank_lines_after_tag/html.html", "--check"] ) + assert ( """+{% extends "nothing.html" %} + @@ -117,6 +118,14 @@ def test_blank_lines_after_tag(runner: CliRunner) -> None: assert """1 file would be updated.""" in result.output assert result.exit_code == 1 + # check blocks that do not start on a newline - they should be left as is. + result = runner.invoke( + djlint, ["tests/config_blank_lines_after_tag/html_three.html", "--check"] + ) + + assert """0 files would be updated.""" in result.output + assert result.exit_code == 0 + def test_profile(runner: CliRunner) -> None: result = runner.invoke(djlint, ["tests/config_profile/html.html"])