mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-04 20:04:42 +00:00
parent
6c2d843c2f
commit
e7c904e8f0
4 changed files with 42 additions and 4 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
<a href="https://www.djlint.com"><img src="https://raw.githubusercontent.com/Riverside-Healthcare/djLint/master/docs/src/static/img/icon.png" alt="djLint Logo" width="270"></a>
|
<a href="https://www.djlint.com"><img src="https://raw.githubusercontent.com/Riverside-Healthcare/djLint/master/docs/src/static/img/icon.png" alt="djLint Logo" width="270"></a>
|
||||||
<br>
|
<br>
|
||||||
</h1>
|
</h1>
|
||||||
<h3 align="center">🙏 Passed 100k downloads! Thank you! 🙏</h3>
|
<h3 align="center">🏗️ Maintainers needed, please reach out on discord or email!</h3>
|
||||||
<h4 align="center">The missing formatter and linter for HTML templates.</h4>
|
<h4 align="center">The missing formatter and linter for HTML templates.</h4>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from functools import partial
|
||||||
|
|
||||||
import regex as re
|
import regex as re
|
||||||
|
|
||||||
from ..helpers import inside_ignored_block
|
from ..helpers import child_of_ignored_block
|
||||||
from ..settings import Config
|
from ..settings import Config
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -115,7 +115,7 @@ def format_attributes(config: Config, html: str, match: re.match) -> str:
|
||||||
"""Spread long attributes over multiple lines."""
|
"""Spread long attributes over multiple lines."""
|
||||||
# check that we are not inside an ignored block
|
# check that we are not inside an ignored block
|
||||||
if (
|
if (
|
||||||
inside_ignored_block(config, html, match)
|
child_of_ignored_block(config, html, match)
|
||||||
or len(match.group(3).strip()) < config.max_attribute_length
|
or len(match.group(3).strip()) < config.max_attribute_length
|
||||||
):
|
):
|
||||||
return match.group()
|
return match.group()
|
||||||
|
|
@ -128,11 +128,11 @@ def format_attributes(config: Config, html: str, match: re.match) -> str:
|
||||||
|
|
||||||
attributes = []
|
attributes = []
|
||||||
|
|
||||||
|
print(match, match.group(3))
|
||||||
# format attributes as groups
|
# format attributes as groups
|
||||||
for attr_grp in re.finditer(
|
for attr_grp in re.finditer(
|
||||||
config.attribute_pattern, match.group(3).strip(), re.VERBOSE
|
config.attribute_pattern, match.group(3).strip(), re.VERBOSE
|
||||||
):
|
):
|
||||||
|
|
||||||
attrib_name = attr_grp.group(1)
|
attrib_name = attr_grp.group(1)
|
||||||
is_quoted = attr_grp.group(2) and attr_grp.group(2)[0] in ["'", '"']
|
is_quoted = attr_grp.group(2) and attr_grp.group(2)[0] in ["'", '"']
|
||||||
quote = attr_grp.group(2)[0] if is_quoted else '"'
|
quote = attr_grp.group(2)[0] if is_quoted else '"'
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,27 @@ def inside_ignored_block(config: Config, html: str, match: re.Match) -> bool:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def child_of_ignored_block(config: Config, html: str, match: re.Match) -> bool:
|
||||||
|
"""Do not add whitespace if the tag is in a non indent block."""
|
||||||
|
return any(
|
||||||
|
ignored_match.start(0) < match.start() and match.end(0) <= ignored_match.end()
|
||||||
|
for ignored_match in list(
|
||||||
|
re.finditer(
|
||||||
|
re.compile(
|
||||||
|
config.ignored_blocks,
|
||||||
|
re.DOTALL | re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||||
|
),
|
||||||
|
html,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
+ list(
|
||||||
|
re.finditer(
|
||||||
|
re.compile(config.ignored_inline_blocks, re.IGNORECASE | re.VERBOSE),
|
||||||
|
html,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def overlaps_ignored_block(config: Config, html: str, match: re.Match) -> bool:
|
def overlaps_ignored_block(config: Config, html: str, match: re.Match) -> bool:
|
||||||
"""Do not add whitespace if the tag is in a non indent block."""
|
"""Do not add whitespace if the tag is in a non indent block."""
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,23 @@ asdf
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
output = reformat(
|
||||||
|
tmp_file,runner,b"""<div><textarea type="textarea" id="messageContent" name="adContent" maxlength="300" class="form-control class_two" rows="10">{{ adContent|default }}</textarea></div>
|
||||||
|
""")
|
||||||
|
|
||||||
|
assert (
|
||||||
|
output.text
|
||||||
|
== """<div>
|
||||||
|
<textarea type="textarea"
|
||||||
|
id="messageContent"
|
||||||
|
name="adContent"
|
||||||
|
maxlength="300"
|
||||||
|
class="form-control class_two"
|
||||||
|
rows="10">{{ adContent|default }}</textarea>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_a_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_a_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
output = reformat(
|
output = reformat(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue