mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-20 10:51:52 +00:00
added fix
This commit is contained in:
parent
53b5b00d7e
commit
814c7b464b
3 changed files with 39 additions and 15 deletions
|
|
@ -48,7 +48,7 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
fr"(<({slt_html})>)(.*?)(</(\2)>)", item, re.IGNORECASE | re.VERBOSE
|
||||
)
|
||||
or re.findall(
|
||||
fr"(<({slt_html})[ ].+?>)(.*?)(</(\2)>)",
|
||||
fr"(<({slt_html})\b.+?>)(.*?)(</(\2)>)",
|
||||
item,
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
|
|
@ -58,12 +58,14 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
re.IGNORECASE | re.MULTILINE | re.VERBOSE,
|
||||
)
|
||||
or re.findall(
|
||||
fr"(<({slt_html})[ ].*?/>)", item, flags=re.IGNORECASE | re.VERBOSE
|
||||
fr"(<({slt_html})\b.*?/>)", item, flags=re.IGNORECASE | re.VERBOSE
|
||||
)
|
||||
or re.findall(
|
||||
fr"(<({always_self_closing_html})[ ].*?/?>)",
|
||||
re.compile(
|
||||
fr"(<({always_self_closing_html})\b.*?/?>)",
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
),
|
||||
item,
|
||||
flags=re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
) and is_block_raw is False:
|
||||
tmp = (indent * indent_level) + item + "\n"
|
||||
|
|
@ -94,9 +96,11 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
# if indent, move right
|
||||
elif (
|
||||
re.search(
|
||||
r"^(?:" + str(config.tag_indent) + r")",
|
||||
re.compile(
|
||||
r"^(?:" + str(config.tag_indent) + r")",
|
||||
re.IGNORECASE | re.MULTILINE | re.VERBOSE,
|
||||
),
|
||||
item,
|
||||
re.IGNORECASE | re.MULTILINE | re.VERBOSE,
|
||||
)
|
||||
and is_block_raw is False
|
||||
):
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ class Config:
|
|||
"""
|
||||
+ self.indent_html_tags
|
||||
+ """
|
||||
)
|
||||
)\\b
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
|
@ -404,7 +404,7 @@ class Config:
|
|||
"""
|
||||
+ self.indent_html_tags
|
||||
+ """
|
||||
)
|
||||
)\\b
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
|
@ -577,7 +577,8 @@ class Config:
|
|||
| with
|
||||
"""
|
||||
|
||||
self.break_html_tags: str = r"""
|
||||
self.break_html_tags: str = (
|
||||
r"""
|
||||
html
|
||||
| head
|
||||
| body
|
||||
|
|
@ -619,11 +620,14 @@ class Config:
|
|||
| svg
|
||||
| h\d
|
||||
| button
|
||||
| img
|
||||
| path
|
||||
| picture
|
||||
| script
|
||||
| style
|
||||
| details
|
||||
| summary
|
||||
| """
|
||||
+ self.always_self_closing_html_tags
|
||||
+ """
|
||||
"""
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ run::
|
|||
pytest tests/test_html.py --cov=src/djlint --cov-branch \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
pytest tests/test_html.py::test_ignored_block --cov=src/djlint --cov-branch \
|
||||
pytest tests/test_html.py::test_self_closing_tags --cov=src/djlint --cov-branch \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
|
|
@ -362,28 +362,44 @@ def test_style_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
assert output["exit_code"] == 0
|
||||
|
||||
|
||||
def test_self_closing_br_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(tmp_file.name, b"""<p><span>Hello</span> <br /> <span>World</span></p>""")
|
||||
def test_self_closing_tags(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<p><span>Hello</span> <br /><input /><link /><img /><source /><meta /> <span>World</span></p>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text()
|
||||
== """<p>
|
||||
<span>Hello</span>
|
||||
<br />
|
||||
<input />
|
||||
<link />
|
||||
<img />
|
||||
<source />
|
||||
<meta />
|
||||
<span>World</span>
|
||||
</p>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_void_br_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(tmp_file.name, b"""<p><span>Hello</span> <br> <span>World</span></p>""")
|
||||
def test_void_self_closing_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<p><span>Hello</span> <br><input><link><img><source><meta> <span>World</span></p>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text()
|
||||
== """<p>
|
||||
<span>Hello</span>
|
||||
<br>
|
||||
<input>
|
||||
<link>
|
||||
<img>
|
||||
<source>
|
||||
<meta>
|
||||
<span>World</span>
|
||||
</p>
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue