fixed #154, added test

This commit is contained in:
Christopher Pickering 2021-12-14 10:24:17 +01:00
parent 736a03307f
commit bec3623a4d
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
3 changed files with 10 additions and 1 deletions

View file

@ -89,7 +89,7 @@ def condense_html(html: str, config: Config) -> str:
# put short template tags back on one line
html = re.sub(
re.compile(
rf"({{%-?[ ]*?({config.optional_single_line_template_tags})[^\n(?:%}})]*?%}})\s*([^%\n]*?)\s*?({{%-?[ ]+?end(\2)[ ]*?%}})",
rf"({{%-?[ ]*?({config.optional_single_line_template_tags})[^\n(?:%}})]*?%}})\s*?([ ]*?[^%\n]*?[ ]*?)\s*?({{%-?[ ]+?end(\2)[ ]*?%}})",
flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE,
),
func,

View file

@ -142,6 +142,7 @@ def indent_html(rawcode: str, config: Config) -> str:
elif is_block_raw is False:
# get leading space, and attributes
func = partial(format_attributes, config)
tmp = re.sub(
re.compile(
fr"(\s*?)(<(?:{config.indent_html_tags})\b)((?:\"[^\"]*\"|'[^']*'|{{[^}}]*}}|[^'\">{{}}])+?)(/?>)",

View file

@ -41,6 +41,14 @@ def test_without_config(runner: CliRunner, tmp_file: TextIO) -> None:
assert output.exit_code == 0
output = reformat(
tmp_file,
runner,
b'<a href="#"\n class="list-group-item{% if not is_allowed %} disabled{% endif %}">foo</a>\n',
)
assert output.exit_code == 0
output = reformat(
tmp_file,
runner,