Skip to content

Commit

Permalink
fix #1052: template tag inside template tag
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverhaas authored Dec 17, 2024
1 parent ad25ce5 commit f2a0a78
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
4 changes: 1 addition & 3 deletions djlint/formatter/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def should_i_move_template_tag(

# break after
return re.sub(
r"((?:{%|{{\#)[ ]*?(?:"
+ config.break_template_tags
+ ")[^}]+?[%}]})(?=[^\n])",
rf"((?:{{%|{{{{\#)[ ]*?(?:{config.break_template_tags})(?>{config.template_tags}|[^}}])+?[%}}]}})(?=[^\n])",
partial(should_i_move_template_tag, "%s\n"),
html,
flags=RE_FLAGS_IMX,
Expand Down
33 changes: 33 additions & 0 deletions tests/test_django/test_templatetag_ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Test template tag extended usage.
uv run pytest tests/test_django/test_templatetag_ext.py
"""

from __future__ import annotations

from typing import TYPE_CHECKING

import pytest

from djlint.reformat import formatter
from tests.conftest import config_builder, printer

if TYPE_CHECKING:
from typing import Any

test_data = [
pytest.param(
('{% component "img" src="{% url \'my_image\' %}" %}'),
('{% component "img" src="{% url \'my_image\' %}" %}\n'),
({"custom_blocks": "component"}),
id="template_tag_inside_template_tag",
)
]


@pytest.mark.parametrize(("source", "expected", "args"), test_data)
def test_base(source: str, expected: str, args: dict[str, Any]) -> None:
output = formatter(config_builder(args), source)

printer(expected, source, output)
assert expected == output

0 comments on commit f2a0a78

Please sign in to comment.