fix(code tags): fixed indentation on code tags w/ trailing text

closes #244
This commit is contained in:
Christopher Pickering 2022-05-12 15:52:58 -05:00
parent 91718e3318
commit a830bc47a2
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
4 changed files with 44 additions and 33 deletions

View file

@ -33,7 +33,6 @@ def expand_html(html: str, config: Config) -> str:
break_char = config.break_before break_char = config.break_before
# html tags - break before # html tags - break before
html = re.sub( html = re.sub(
re.compile( re.compile(
rf"{break_char}\K(</?(?:{html_tags})\b(\"[^\"]*\"|'[^']*'|{{[^}}]*}}|[^'\">{{}}])*>)", rf"{break_char}\K(</?(?:{html_tags})\b(\"[^\"]*\"|'[^']*'|{{[^}}]*}}|[^'\">{{}}])*>)",

View file

@ -63,13 +63,13 @@ def indent_html(rawcode: str, config: Config) -> str:
# if a one-line, inline tag, just process it, only if line starts w/ it # if a one-line, inline tag, just process it, only if line starts w/ it
elif ( elif (
re.findall( re.findall(
rf"(<({slt_html})>)(.*?)(</(\2)>$)", rf"(<({slt_html})>)(.*?)(</(\2)>[^<]*?$)",
item, item,
re.IGNORECASE | re.VERBOSE | re.MULTILINE, re.IGNORECASE | re.VERBOSE | re.MULTILINE,
) )
or re.findall( or re.findall(
re.compile( re.compile(
rf"(<({slt_html})\b.+?>)(.*?)(</(\2)>$)", rf"(<({slt_html})\b.+?>)(.*?)(</(\2)>[^<]*?$)",
re.IGNORECASE | re.VERBOSE | re.MULTILINE, re.IGNORECASE | re.VERBOSE | re.MULTILINE,
), ),
item, item,

View file

@ -530,36 +530,6 @@ class Config:
) )
""" """
# the contents of these tag blocks will be indented, then unindented
self.tag_indent: str = (
self.template_indent
+ """
| (?:<
(?:
"""
+ self.indent_html_tags
+ """
)\\b
)
"""
)
self.tag_unindent: str = (
r"""
^
"""
+ self.template_unindent
+ """
| (?:</
(?:
"""
+ self.indent_html_tags
+ """
)\\b
)
"""
)
# these tags should be unindented and next line will be indented # these tags should be unindented and next line will be indented
self.tag_unindent_line: str = r""" self.tag_unindent_line: str = r"""
(?:\{%-?[ ]*?(?:elif|else|empty)) (?:\{%-?[ ]*?(?:elif|else|empty))
@ -835,3 +805,33 @@ class Config:
+ """ + """
""" """
) )
# the contents of these tag blocks will be indented, then unindented
self.tag_indent: str = (
self.template_indent
+ """
| (?:<
(?:
"""
+ self.indent_html_tags
+ """
)\\b
)
"""
)
self.tag_unindent: str = (
r"""
^
"""
+ self.template_unindent
+ """
| (?:</
(?:
"""
+ self.indent_html_tags
+ """
)\\b
)
"""
)

View file

@ -33,6 +33,18 @@ layout: <div><div></div></div>
assert output.exit_code == 0 assert output.exit_code == 0
def test_code_tag(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<ol>
<li>
<code>a</code> b
</li>
</ol>""",
)
assert output.exit_code == 0
def test_pre_tag(runner: CliRunner, tmp_file: TextIO) -> None: def test_pre_tag(runner: CliRunner, tmp_file: TextIO) -> None:
# added for https://github.com/Riverside-Healthcare/djLint/issues/187 # added for https://github.com/Riverside-Healthcare/djLint/issues/187
output = reformat( output = reformat(