diff --git a/src/djlint/formatter/css.py b/src/djlint/formatter/css.py index be6be26..49ba80c 100644 --- a/src/djlint/formatter/css.py +++ b/src/djlint/formatter/css.py @@ -37,7 +37,7 @@ def format_css(html: str, config: Config) -> str: line = line.lstrip() ignore_indent = False - if ignore_indent is False: + if ignore_indent is False and line: beautified += "\n" + inner_indent + line else: diff --git a/src/djlint/formatter/js.py b/src/djlint/formatter/js.py index b7f9e0f..b846686 100644 --- a/src/djlint/formatter/js.py +++ b/src/djlint/formatter/js.py @@ -38,9 +38,9 @@ def format_js(html: str, config: Config) -> str: line = line.lstrip() ignore_indent = False - if ignore_indent is False: - + if ignore_indent is False and line: beautified += "\n" + inner_indent + line + else: beautified += "\n" + line diff --git a/tests/test_config/test_scripts_styles/blank_lines.html b/tests/test_config/test_scripts_styles/blank_lines.html new file mode 100644 index 0000000..0460e6d --- /dev/null +++ b/tests/test_config/test_scripts_styles/blank_lines.html @@ -0,0 +1,14 @@ + +
+ + + + diff --git a/tests/test_config/test_scripts_styles/test_config.py b/tests/test_config/test_scripts_styles/test_config.py index 73d97b8..8888d4c 100644 --- a/tests/test_config/test_scripts_styles/test_config.py +++ b/tests/test_config/test_scripts_styles/test_config.py @@ -35,3 +35,14 @@ def test_ignore(runner: CliRunner) -> None: ], ) assert result.exit_code == 0 + + +def text_blank_lines(runner: CliRunner) -> None: + result = runner.invoke( + djlint, + [ + "tests/test_config/test_scripts_styles/blank_lines.html", + "--check", + ], + ) + assert result.exit_code == 0