Skip to content

Commit

Permalink
fix(formatter): fixed function formatting with nested quoted parenthesis
Browse files Browse the repository at this point in the history
closes #698
  • Loading branch information
christopherpickering committed Jun 26, 2023
1 parent bc15080 commit 6d63a6a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
28 changes: 14 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/djlint/formatter/indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def format_function(config: Config, html: str, match: re.Match) -> str:
# format function contents
beautified_code = re.sub(
re.compile(
r"([ ]*)({{-?\+?)[ ]*?((?:(?!}}).)*?\w)(\([^\)]*?\)[ ]*)((?:(?!}}).)*?-?\+?}})",
r"([ ]*)({{-?\+?)[ ]*?((?:(?!}}).)*?\w)(\((?:\"[^\"]*\"|'[^']*'|[^\)])*?\)[ ]*)((?:(?!}}).)*?-?\+?}})",
flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE | re.DOTALL,
),
func,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_nunjucks/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
({}),
id="long line",
),
pytest.param(
('<span class="nav">{{ _("Orders (Selling)") }}</span>'),
('<span class="nav">{{ _("Orders (Selling)") }}</span>\n'),
({}),
id="test quoting",
),
pytest.param(
(
"{{ myfunc({\n"
Expand Down

0 comments on commit 6d63a6a

Please sign in to comment.