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

[BUG] [Formatter] long textarea in twig - line wrapping does not work #486

Closed
3 tasks done
palansher opened this issue Dec 15, 2022 · 16 comments · Fixed by #487 or #489
Closed
3 tasks done

[BUG] [Formatter] long textarea in twig - line wrapping does not work #486

palansher opened this issue Dec 15, 2022 · 16 comments · Fixed by #487 or #489
Labels

Comments

@palansher
Copy link

palansher commented Dec 15, 2022

Issue

Your Djlint becomes better and better. Thank you!

How To Reproduce

I cannot reformat such long lines

<textarea type="textarea" id="messageContent" name="adContent" maxlength="300" class="form-control" rows="10">{{ adContent|default }}</textarea>

for like this:

<textarea 
               type="textarea" 
               id="messageContent" 
               name="adContent" 
               maxlength="300"  
               class="form-control" 
               rows="10">
               {{ adContent|default }}
</textarea>

It still one long line.
Same time, the long 'inputs' and 'divs' are wrapped well.

Please give your helping hand!


BTW,

By, according to my observations, for textareas

this style

<textarea 
               content</textarea>

is more prefferable then this

<textarea 
               content
</textarea>

Because in the second variant the browser adds extra ugly <CR/LF> trash to the end of content of textarea field.
It happens when we have the combination of next three consistently: "content text" + line feed + "</textarea>".
So, the middle line feed makes the problem.


my conf:

.djlintrc

{
    "ignore": "H021,H030,H031,H017,H023,H014,H006",
    "extension": "twig",
    "indent": "4",
    "profile": "nunjucks",
    "format_attribute_template_tags": false,
    "max_line_length": "110",
    "max_attribute_length": "100",
    "preserve_blank_lines": "true"
}

System Info

  • OS: e.g. ubuntu 20.04
  • Python Version 3.8.10
  • djLint Version 1.19.7
  • template language: twig
@palansher palansher added 🦠 bug Something isn't working 🧽 formatter labels Dec 15, 2022
christopherpickering pushed a commit that referenced this issue Dec 15, 2022
## [1.19.8](v1.19.7...v1.19.8) (2022-12-15)

### Bug Fixes

* **attributes:** fixed outer quotes being stripped from attribute values ([dff02dc](dff02dc)), closes [#471](#471)
* **settings:** fixed pyproject loader ([5890161](5890161)), closes [#469](#469)
* **textarea:** fixed textarea attribute formatting ([e7c904e](e7c904e)), closes [#486](#486)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.19.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

@palansher
Copy link
Author

🎉 This issue has been resolved in version 1.19.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Hello Chris!

Unfortunately, no change for textarea.

vladp@dev:~$ djlint --version
djlint, version 1.19.8

This code

<textarea type="textarea" id="messageContent" name="adContent" maxlength="300" class="form-control" rows="10">{{ adContent|default }}</textarea>

is reformatting to one line back even if I format it manually and the settings are:

"max_line_length": "110",
"max_attribute_length": "100",

I extracted this textarea attribute alone to separate file. No Changes.

@palansher
Copy link
Author

Even out of VS code extension:

djlint --reformat test.html.twig 

Reformatting 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00    


0 files were updated.

✔ ~/dev/gtdev-advert/templates/admin/app [advert|✚ 7…3] 
15:34 $ cat test.html.twig 
<textarea type="textarea" id="messageContent" name="adContent" maxlength="300" class="form-control" rows="10">{{ adContent|default }}</textarea>

@christopherpickering
Copy link
Contributor

christopherpickering commented Dec 16, 2022

@palansher
Copy link
Author

BTW:
I just noticed that my 'type="textarea"' inside <textarea> tag is non-standard, according https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea.

I removed it and .. no changes.

@christopherpickering
Copy link
Contributor

no problem, we don't check for anything being standard except for changing case ;)

@christopherpickering
Copy link
Contributor

I tried it out in the online demo and it is working:

image

can you send more surrounding html or a full file?

@palansher
Copy link
Author

palansher commented Dec 16, 2022

Holy cow ! You have demo page!!

hope, files can help:
files.zip

@palansher
Copy link
Author

palansher commented Dec 16, 2022

hmm, I have cleaned up (just left {} ) config file and vua-la, it formats well!!!

But I see nothing illegal inside it (included in zip above).

@christopherpickering
Copy link
Contributor

thanks! I'll check it out!

@christopherpickering
Copy link
Contributor

I think I found the bug.. I'll see about getting a change out soon.

the --check flag + stdin was not writing the formatted code back and just retuning the original.

christopherpickering added a commit that referenced this issue Dec 16, 2022
…tted output

stdin with --check was returning the original code, but should be returning the formatted code.

closes #486
christopherpickering pushed a commit that referenced this issue Dec 16, 2022
## [1.19.9](v1.19.8...v1.19.9) (2022-12-16)

### Bug Fixes

* **stdin --check:** stdin with the --check flag should return a formatted output ([57e1eec](57e1eec)), closes [#486](#486)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.19.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

@palansher
Copy link
Author

palansher commented Dec 16, 2022

Alas! the same:

21:08 $ djlint --reformat test.html.twig 

Reformatting 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00    


0 files were updated.

✔ ~/dev/gtdev-advert/templates/admin/app [advert|✚ 12…5] 
21:08 $ djlint --version
djlint, version 1.19.9
✔ ~/dev/gtdev-advert/templates/admin/app [advert|✚ 12…5] 
21:08 $ cat test.html.twig 
<textarea type="textarea" id="messageContent" name="adContent" maxlength="300" class="form-control" rows="10">{{ adContent|default }}</textarea>
✔ ~/dev/gtdev-advert/templates/admin/app [advert|✚ 12…5] 

config is the same:

✔ ~/dev/gtdev-advert [advert|✚ 12…5] 
21:11 $ cat .djlintrc 
{
    "ignore": "H021,H030,H031,H017,H023,H014,H006",
    "extension": "twig",
    "indent": "4",
    "profile": "nunjucks",
    "format_attribute_template_tags": false,
    "max_line_length": "110",
    "max_attribute_length": "100",
    "preserve_blank_lines": "true"

}

@christopherpickering
Copy link
Contributor

ty, will keep looking :) Your bugs always escape..

@christopherpickering
Copy link
Contributor

@palansher try reducing the max_attribute_length to something smaller, or even 0 if you want attributes to always be formatted.

{
    "ignore": "H021,H030,H031,H017,H023,H014,H006",
    "extension": "twig",
    "indent": "4",
    "profile": "nunjucks",
    "format_attribute_template_tags": false,
    "max_line_length": "110",
    "max_attribute_length": "50",
    "preserve_blank_lines": "true"

}

will make it format.

@christopherpickering
Copy link
Contributor

@palansher hope things are well, haven't heard from you here in a while 😅 no bugs I guess 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants