djLint
djLint copied to clipboard
[BUG] [Formatter] Nunjucks function expressions have incorrect indent
- [x] I'm on the latest version of djLint
- [x] I've searched the issues
- [x] I've read the docs
System Info
- OS: windown 10
- Python Version (3.12.1)
- djLint Version (1.34.1)
- template language: nunjucks
Issue
I get incorrect indentations in {{ }} expression when formatting njk files with djlint. The only workaround I have for now is keep preserve_leading_space to true but i actually want them to be formatted as well.
I also tried online version and got the same result.
Don't know is it something with my config or with djlint. Please help. Looks like this is the only solution for now to format nunjucks templates.
How To Reproduce
.djlintrc:
{
"extension": "njk",
"profile": "nunjucks",
"indent": 4,
"no_function_formatting": false,
"preserve_leading_space": false
}
command:
djlint ./src --reformat --configuration .djlintrc
sample input:
<div>
{% if apos %}
{{ apos.singleton(data.global, "footerHead", 'apostrophe-rich-text', {
toolbar: [ 'Styles', 'Bold', 'Italic', 'Link', 'Unlink' ],
styles: [
{
name: 'footerHead',
element: 'div',
attributes: { class: 'footer--title-main'}
}
]
}) }}
{% endif %}
</div>
<div>
{{ funct({
test: 'best',
jest: 'test',
fest: 'pest'}) }}
</div>
output:
<div>
{% if apos %}
{{ apos.singleton(data.global, "footerHead", 'apostrophe-rich-text', {
toolbar: [ 'Styles', 'Bold', 'Italic', 'Link', 'Unlink' ],
styles: [
{
name: 'footerHead',
element: 'div',
attributes: { class: 'footer--title-main'}
}
]
}) }}
{% endif %}
</div>
<div>{{ funct({"test": "best", "jest": "test", "fest": "pest"}) }}</div>