mirror of
https://github.com/Hopiu/djLint.git
synced 2026-04-02 05:30:24 +00:00
fix(code tags): fixed indentation on code tags w/ trailing text
closes #244
This commit is contained in:
parent
91718e3318
commit
a830bc47a2
4 changed files with 44 additions and 33 deletions
|
|
@ -33,7 +33,6 @@ def expand_html(html: str, config: Config) -> str:
|
|||
break_char = config.break_before
|
||||
|
||||
# html tags - break before
|
||||
|
||||
html = re.sub(
|
||||
re.compile(
|
||||
rf"{break_char}\K(</?(?:{html_tags})\b(\"[^\"]*\"|'[^']*'|{{[^}}]*}}|[^'\">{{}}])*>)",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
elif (
|
||||
re.findall(
|
||||
rf"(<({slt_html})>)(.*?)(</(\2)>$)",
|
||||
rf"(<({slt_html})>)(.*?)(</(\2)>[^<]*?$)",
|
||||
item,
|
||||
re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||
)
|
||||
or re.findall(
|
||||
re.compile(
|
||||
rf"(<({slt_html})\b.+?>)(.*?)(</(\2)>$)",
|
||||
rf"(<({slt_html})\b.+?>)(.*?)(</(\2)>[^<]*?$)",
|
||||
re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||
),
|
||||
item,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
self.tag_unindent_line: str = r"""
|
||||
(?:\{%-?[ ]*?(?: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
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,18 @@ layout: <div><div></div></div>
|
|||
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:
|
||||
# added for https://github.com/Riverside-Healthcare/djLint/issues/187
|
||||
output = reformat(
|
||||
|
|
|
|||
Loading…
Reference in a new issue