diff --git a/src/djlint/formatter/compress_html.py b/src/djlint/formatter/compress_html.py index f8b7baa..5979ce3 100644 --- a/src/djlint/formatter/compress_html.py +++ b/src/djlint/formatter/compress_html.py @@ -43,4 +43,16 @@ def compress_html(html: str, config: Config) -> str: html, ) + # should we add blank lines after load tags? + if config.blank_line_after_tag: + for tag in [x.strip() for x in config.blank_line_after_tag.split(",")]: + html = re.sub( + re.compile( + fr"((?:{{%\s*?{tag}[^}}]+?%}}\n?)+)", + re.IGNORECASE | re.MULTILINE | re.DOTALL, + ), + r"\1\n", + html, + ) + return html diff --git a/src/djlint/formatter/indent_html.py b/src/djlint/formatter/indent_html.py index 8098741..a4e48b5 100644 --- a/src/djlint/formatter/indent_html.py +++ b/src/djlint/formatter/indent_html.py @@ -110,13 +110,9 @@ def indent_html(rawcode: str, config: Config) -> str: elif is_raw_first_line is True: tmp = (indent * indent_level) + item + "\n" - elif is_block_raw is True: + elif is_block_raw is True or item.strip() == "": tmp = item + "\n" - # if just a blank line - elif item.strip() == "": - tmp = item.strip() - # otherwise, just leave same level else: tmp = (indent * indent_level) + item + "\n" @@ -160,16 +156,4 @@ def indent_html(rawcode: str, config: Config) -> str: beautified_code = beautified_code + tmp - # should we add blank lines after load tags? - if config.blank_line_after_tag: - for tag in [x.strip() for x in config.blank_line_after_tag.split(",")]: - beautified_code = re.sub( - re.compile( - fr"((?:{{%\s*?{tag}[^}}]+?%}}\n?)+)", - re.IGNORECASE | re.MULTILINE | re.DOTALL, - ), - r"\1\n", - beautified_code, - ) - return beautified_code.strip() + "\n" diff --git a/src/djlint/lint.py b/src/djlint/lint.py index 19b95a4..fb90539 100644 --- a/src/djlint/lint.py +++ b/src/djlint/lint.py @@ -61,7 +61,7 @@ def lint_file(config: Config, this_file: Path) -> Dict: # rule H025 is a special case where the output must be an even num. if rule["name"] == "H025": - open_tags = [] + open_tags: List[re.Match] = [] for match in re.finditer( re.compile( diff --git a/tests/config_blank_lines_after_tag/html_five.html b/tests/config_blank_lines_after_tag/html_five.html new file mode 100644 index 0000000..036ee35 --- /dev/null +++ b/tests/config_blank_lines_after_tag/html_five.html @@ -0,0 +1,4 @@ +