Skip to content

Commit

Permalink
fix(custom tags): fixed issue where end tag for custom block was not …
Browse files Browse the repository at this point in the history
…de-indented

Auto add end tags to the custom tag list.

closes #572
  • Loading branch information
christopherpickering committed Apr 4, 2023
1 parent 600d6b3 commit fb8bf5e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/djlint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def load_custom_rules(src: Path) -> List:
def build_custom_blocks(custom_blocks: Union[str, None]) -> Optional[str]:
"""Build regex string for custom template blocks."""
if custom_blocks:
return "|" + "|".join(x.strip() for x in custom_blocks.split(","))
# need to also do "end<tag>"
open_tags = [x.strip() for x in custom_blocks.split(",")]
close_tags = ["end" + x.strip() for x in custom_blocks.split(",")]
return "|" + "|".join(list(set(open_tags + close_tags)))
return None


Expand Down
2 changes: 2 additions & 0 deletions tests/test_config/test_custom_tags/html.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{% example stuff %}<p>this is a very very long paragraph that does nothing except be a long paragraph asdfasdfasdfasdfasdf fasdf asdfasdfasdf</p>{% endexample %}

{% verylongexampletagthatiskindaneattolookat stuff%}{{ tag }}{% endverylongexampletagthatiskindaneattolookat %}
2 changes: 1 addition & 1 deletion tests/test_config/test_custom_tags/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[tool]
[tool.djlint]
custom_blocks = "toc,example"
custom_blocks = "toc,example,verylongexampletagthatiskindaneattolookat"
7 changes: 6 additions & 1 deletion tests/test_config/test_custom_tags/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ def test_custom_tags(runner: CliRunner) -> None:
result = runner.invoke(
djlint, ["tests/test_config/test_custom_tags/html.html", "--check"]
)
print(result.output)

assert (
"""-{% example stuff %}<p>this is a very very long paragraph that does nothing except be a long paragraph asdfasdfasdfasdfasdf fasdf asdfasdfasdf</p>{% endexample %}
-
-{% verylongexampletagthatiskindaneattolookat stuff%}{{ tag }}{% endverylongexampletagthatiskindaneattolookat %}
+{% example stuff %}
+ <p>
+ this is a very very long paragraph that does nothing except be a long paragraph asdfasdfasdfasdfasdf fasdf asdfasdfasdf
+ </p>
+{% endexample %}
+{% verylongexampletagthatiskindaneattolookat stuff %}
+ {{ tag }}
+{% endverylongexampletagthatiskindaneattolookat %}
"""
in result.output
)
Expand Down

0 comments on commit fb8bf5e

Please sign in to comment.