mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-31 04:30:28 +00:00
updated blank lines setup
This commit is contained in:
parent
535eb9d659
commit
a0847aaec9
4 changed files with 36 additions and 16 deletions
|
|
@ -27,17 +27,45 @@ def condense_html(html: str, config: Config) -> str:
|
|||
|
||||
html = re.sub(re.compile(r"^[ \t]*(.*?)[\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."""
|
||||
if config.blank_line_after_tag:
|
||||
return not any(
|
||||
re.findall(
|
||||
re.compile(
|
||||
fr"((?:{{%\s*?{tag}[^}}]+?%}}\n?)+)",
|
||||
re.IGNORECASE | re.MULTILINE | re.DOTALL,
|
||||
),
|
||||
html,
|
||||
)
|
||||
for tag in [x.strip() for x in config.blank_line_after_tag.split(",")]
|
||||
)
|
||||
return True
|
||||
|
||||
def condense_line(config: Config, match: re.Match) -> str:
|
||||
"""Put contents on a single line if below max line length."""
|
||||
if (
|
||||
len(match.group(1) + match.group(3) + match.group(4))
|
||||
< config.max_line_length
|
||||
):
|
||||
) and if_blank_line_after_match(config, match.group(3)):
|
||||
return match.group(1) + match.group(3) + match.group(4)
|
||||
|
||||
return match.group()
|
||||
|
||||
func = partial(condense_line, config)
|
||||
|
||||
# should we add blank lines after load tags?
|
||||
if config.blank_line_after_tag:
|
||||
for tag in [x.strip() for x in config.blank_line_after_tag.split(",")]:
|
||||
html = re.sub(
|
||||
re.compile(
|
||||
fr"((?:{{%\s*?{tag}[^}}]+?%}}\n?)+)",
|
||||
re.IGNORECASE | re.MULTILINE | re.DOTALL,
|
||||
),
|
||||
r"\1\n",
|
||||
html,
|
||||
)
|
||||
|
||||
# put short single line tags on one line
|
||||
html = re.sub(
|
||||
re.compile(
|
||||
|
|
@ -59,16 +87,4 @@ def condense_html(html: str, config: Config) -> str:
|
|||
html,
|
||||
)
|
||||
|
||||
# should we add blank lines after load tags?
|
||||
if config.blank_line_after_tag:
|
||||
for tag in [x.strip() for x in config.blank_line_after_tag.split(",")]:
|
||||
html = re.sub(
|
||||
re.compile(
|
||||
fr"((?:{{%\s*?{tag}[^}}]+?%}}\n?)+)",
|
||||
re.IGNORECASE | re.MULTILINE | re.DOTALL,
|
||||
),
|
||||
r"\1\n",
|
||||
html,
|
||||
)
|
||||
print(html)
|
||||
return html
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<tr>
|
||||
<td rowspan="{{ quality.row_span }}">{% include "common/pdfs/partials/display_quality_improvements.html" %}
|
||||
<td rowspan="{{ quality.row_span }}">
|
||||
{% include "common/pdfs/partials/display_quality_improvements.html" %}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<div class="tab-cnt">
|
||||
<div class="tab-dta active" id="details">
|
||||
<div class="em-grid">{% include "pages/task/details_source.html.j2" %}
|
||||
<div class="em-grid">
|
||||
{% include "pages/task/details_source.html.j2" %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ run::
|
|||
|
||||
for a single test, run::
|
||||
|
||||
pytest tests/test_config.py::test_require_pragma --cov=src/djlint \
|
||||
pytest tests/test_config.py::test_blank_lines_after_tag --cov=src/djlint \
|
||||
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue