fix tag indent for preserve whitespace option, preserve better text indenting

This commit is contained in:
Christopher Pickering 2022-06-16 06:41:49 -05:00
parent 15ead700d1
commit dc9a97d510
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 14 additions and 1 deletions

View file

@ -26,7 +26,15 @@ def condense_html(html: str, config: Config) -> str:
func = partial(strip_space, config, html)
if not config.preserve_leading_space:
# remove any leading/trailing space
html = re.sub(re.compile(r"^[ \t]*(.*?)[\n \t]*$", re.M), func, html)
else:
# only remove leading space in front of tags
# <, {%, {#, {{
html = re.sub(
re.compile(r"^[ \t]*((?:<|{%|{#|{{).*?)[\n \t]*$", re.M), func, html
)
html = re.sub(re.compile(r"^(.*?)[\n \t]*$", re.M), func, html)
def if_blank_line_after_match(config: Config, html: str) -> bool:
"""Check if there should be a blank line after."""

View file

@ -161,7 +161,12 @@ def indent_html(rawcode: str, config: Config) -> str:
# otherwise, just leave same level
else:
tmp = (indent * indent_level) + item + "\n"
if not config.preserve_leading_space:
# if we are not trying to preserve indenting
# on text, the add it now.
tmp = (indent * indent_level) + item + "\n"
else:
tmp = item + "\n"
# if a opening raw tag then start ignoring.. only if there is no closing tag
# on the same line