Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1052: template tag inside template tag #1053

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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