Skip to content

Commit

Permalink
fix(preserving space): misc improvements for the preserve leading spa…
Browse files Browse the repository at this point in the history
…ce option

with this option specified tags will not be condensed back to one line. Template {{ }} tags will
also be treated as text and the existing indent respected.

closes #566
  • Loading branch information
christopherpickering committed Apr 4, 2023
1 parent 120460d commit 03ee6f0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/djlint/formatter/condense.py
Expand Up @@ -43,11 +43,9 @@ def strip_space(config: Config, html: str, match: re.Match) -> str:

else:
# only remove leading space in front of tags
# <, {%, {#, {{
# <, {%
html = re.sub(
re.compile(
rf"^[ \t]*((?:<|{{%|{{\#|{{{{).*?)[{trailing_contents}]*$", re.M
),
re.compile(rf"^[ \t]*((?:<|{{%).*?)[{trailing_contents}]*$", re.M),
func,
html,
)
Expand Down Expand Up @@ -106,6 +104,10 @@ def add_blank_line_before(config: Config, html: str, match: re.Match) -> str:

def condense_html(html, config):
"""Put short tags back on a single line."""
if config.preserve_leading_space:
# if a user is attempting to reuse any leading
# space for other purposes, we should not try to remove it.
return html

def condense_line(config: Config, match: re.Match) -> str:
"""Put contents on a single line if below max line length."""
Expand Down

0 comments on commit 03ee6f0

Please sign in to comment.