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] </textarea> dedents weirdly #938

Open
3 tasks done
mousetail opened this issue Oct 12, 2024 · 3 comments
Open
3 tasks done

[BUG] [Formatter] </textarea> dedents weirdly #938

mousetail opened this issue Oct 12, 2024 · 3 comments
Labels
🦠 bug Something isn't working 🧽 formatter

Comments

@mousetail
Copy link

System Info

  • OS: Ubuntu 20.04.5
  • Python: 3.10.12
  • djLint Version (djlint --version): 1.35.2
  • template language: Tera, I'm using the Jinja profile for djLint

Issue

Multiline <textarea> block dedent completely.

DJLint formats the code as follows:

<form method="post">
  <textarea name="code">
    {%- if object.code -%}
      {{- object.code -}}
    {%- endif -%}
</textarea>
  <input>
</form>

But I expect lie this:

<form method="post">
  <textarea name="code">
    {%- if object.code -%}
      {{- object.code -}}
    {%- endif -%}
  </textarea>
  <input>
</form>

How To Reproduce

Try to format the code above. Settings are default.

@mousetail mousetail added 🦠 bug Something isn't working 🧽 formatter labels Oct 12, 2024
@mousetail mousetail changed the title [BUG] [Formatter] [BUG] [Formatter] </textarea> dedents weirdly Oct 12, 2024
@oliverhaas
Copy link
Contributor

oliverhaas commented Nov 19, 2024

Have you looked at how the textarea you have defined would look like in a browser? textarea is sensitive to indenting, so it does not makes sense for djlint to format it imo, and that's why djlint (intentionally, I think) has textarea in its ignored_blocks.

image

EDIT: So your code should be

<form method="post">
  <textarea name="code">{%- if object.code -%}{{- object.code -}}{%- endif -%}</textarea>
  <input>
</form>

Not nice, but fine, and I don't see an actually better way.

@mousetail
Copy link
Author

In Jinja {- removes whitespace from the ends of a statement. A textarea with {- -} inside it should just be formatted normally.

@oliverhaas
Copy link
Contributor

oliverhaas commented Nov 19, 2024

Okay. I did not know about that. Apparently Jinja also has some env variables which might affect whitespace handling.

Then my best guess to make your specific case work you would need djlint to respect jinja whitespace-removal by template tags in multiple places. Such that a textarea block which both starts and ends with whitespace-removal will be indented like normal html blocks.

If you wanna take a shot I would look for something like ignored_blocks and regexes which include textarea (obviously). Might be just a couple of lines and a test case (which you already have).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦠 bug Something isn't working 🧽 formatter
Projects
None yet
Development

No branches or pull requests

2 participants