updated blank lines setup

This commit is contained in:
Christopher Pickering 2021-10-15 09:15:00 +03:00
parent 535eb9d659
commit a0847aaec9
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
4 changed files with 36 additions and 16 deletions

View file

@ -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

View file

@ -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>

View file

@ -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>

View file

@ -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
"""