diff --git a/README.md b/README.md index 7cf124e..301ce79 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ djLint Logo
-

🙏 Passed 100k downloads! Thank you! 🙏

+

🏗️ Maintainers needed, please reach out on discord or email!

The missing formatter and linter for HTML templates.

diff --git a/src/djlint/formatter/attributes.py b/src/djlint/formatter/attributes.py index ff390bc..0bb43e9 100644 --- a/src/djlint/formatter/attributes.py +++ b/src/djlint/formatter/attributes.py @@ -4,7 +4,7 @@ from functools import partial import regex as re -from ..helpers import inside_ignored_block +from ..helpers import child_of_ignored_block from ..settings import Config @@ -115,7 +115,7 @@ def format_attributes(config: Config, html: str, match: re.match) -> str: """Spread long attributes over multiple lines.""" # check that we are not inside an ignored block if ( - inside_ignored_block(config, html, match) + child_of_ignored_block(config, html, match) or len(match.group(3).strip()) < config.max_attribute_length ): return match.group() @@ -128,11 +128,11 @@ def format_attributes(config: Config, html: str, match: re.match) -> str: attributes = [] + print(match, match.group(3)) # format attributes as groups for attr_grp in re.finditer( config.attribute_pattern, match.group(3).strip(), re.VERBOSE ): - attrib_name = attr_grp.group(1) is_quoted = attr_grp.group(2) and attr_grp.group(2)[0] in ["'", '"'] quote = attr_grp.group(2)[0] if is_quoted else '"' diff --git a/src/djlint/helpers.py b/src/djlint/helpers.py index 2d9de34..9b11917 100644 --- a/src/djlint/helpers.py +++ b/src/djlint/helpers.py @@ -122,6 +122,27 @@ def inside_ignored_block(config: Config, html: str, match: re.Match) -> bool: ) ) +def child_of_ignored_block(config: Config, html: str, match: re.Match) -> bool: + """Do not add whitespace if the tag is in a non indent block.""" + return any( + ignored_match.start(0) < match.start() and match.end(0) <= ignored_match.end() + for ignored_match in list( + re.finditer( + re.compile( + config.ignored_blocks, + re.DOTALL | re.IGNORECASE | re.VERBOSE | re.MULTILINE, + ), + html, + ) + ) + + list( + re.finditer( + re.compile(config.ignored_inline_blocks, re.IGNORECASE | re.VERBOSE), + html, + ) + ) + ) + def overlaps_ignored_block(config: Config, html: str, match: re.Match) -> bool: """Do not add whitespace if the tag is in a non indent block.""" diff --git a/tests/test_html/test_tag_textarea.py b/tests/test_html/test_tag_textarea.py index f058654..faebcba 100644 --- a/tests/test_html/test_tag_textarea.py +++ b/tests/test_html/test_tag_textarea.py @@ -68,6 +68,23 @@ asdf """ ) + output = reformat( + tmp_file,runner,b"""

+""") + + assert ( + output.text + == """
+ +
+""" + ) + def test_a_tag(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat(