Skip to content

Commit

Permalink
fix(formatter): fixed line_break_after_multiline_tag to force break…
Browse files Browse the repository at this point in the history
… in all cases

closes #680
  • Loading branch information
christopherpickering committed Jun 12, 2023
1 parent 4a7897f commit 3b37ec8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/djlint/formatter/condense.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ def condense_html(html, config):

def condense_line(config: Config, html: str, match: re.Match) -> str:
"""Put contents on a single line if below max line length."""
# match.group(1) contains the opening tag, which may be split over multiple lines
if config.line_break_after_multiline_tag:
combined_length = len(match.group(1) + match.group(3) + match.group(4))
# always force a break by pretending the line is too long.
combined_length = config.max_line_length + 1
else:
combined_length = len(
match.group(1).splitlines()[-1] + match.group(3) + match.group(4)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests html details/summary tag.
"""Tests forced line break when a tag has breaks in attributes tag.
poetry run pytest tests/test_html/test_tag_details_summary.py
poetry run pytest tests/test_config/test_line_break_after_multiline_tag.py
"""
import pytest

Expand Down Expand Up @@ -84,6 +84,38 @@
({"line_break_after_multiline_tag": True}),
id="line_break_after_multiline_tag_when_already_condensed",
),
pytest.param(
(
'<div class="ds-flex ds-items-center ds-justify-center"\n'
' style="grid-column: 3/4">\n'
" {{ here_is_a_long_variable }}\n"
"</div>\n"
'<a class="ds-flex ds-items-center ds-justify-center"\n'
' style="grid-column: 3/4">\n'
" {{ here_is_a_long_variable }}\n"
"</a>\n"
'<span class="ds-flex ds-items-center ds-justify-center"\n'
' style="grid-column: 3/4">\n'
" {{ here_is_a_long_variable }}\n"
"</span>\n"
),
(
'<div class="ds-flex ds-items-center ds-justify-center"\n'
' style="grid-column: 3/4">\n'
" {{ here_is_a_long_variable }}\n"
"</div>\n"
'<a class="ds-flex ds-items-center ds-justify-center"\n'
' style="grid-column: 3/4">\n'
" {{ here_is_a_long_variable }}\n"
"</a>\n"
'<span class="ds-flex ds-items-center ds-justify-center"\n'
' style="grid-column: 3/4">\n'
" {{ here_is_a_long_variable }}\n"
"</span>\n"
),
({"line_break_after_multiline_tag": True}),
id="more complex tags. #680",
),
]


Expand Down

0 comments on commit 3b37ec8

Please sign in to comment.