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

Indention bug with Stimulus action #57

Closed
michael-yin opened this issue Feb 22, 2022 · 4 comments · Fixed by #62
Closed

Indention bug with Stimulus action #57

michael-yin opened this issue Feb 22, 2022 · 4 comments · Fixed by #62

Comments

@michael-yin
Copy link

If we have a simple test.html file

<div>
  <div data-action="click->modal#closeBackground">
  </div>
</div>

If I run djhtml -i test.html

I got

<div>
    <div data-action="click->modal#closeBackground">
    </div>
    </div>

As you can see, the last </div> indention is not correct.

The click->modal#closeBackground caused this problem.

@JaapJoris
Copy link
Member

JaapJoris commented Feb 24, 2022

I thought it was illegal to use unencoded < and > characters inside HTML attributes, but I could only find this paragraph about it in the (outdated) HTML 4 standard:

authors should use "&gt;" (ASCII decimal 62) in text instead of ">" to avoid problems with older user agents that incorrectly perceive this as the end of a tag (tag close delimiter) when it appears in quoted attribute values.

So I guess until this bug is fixed DjHTML should be considered an "older user agent" :-)

@spookylukey
Copy link

Similar problems here, using alpine if and things like x-if="currentStep > step.number"

Past behaviour was different - I narrowed the change down to between 1.4.12 and 1.4.13.

@michael-yin
Copy link
Author

I checked djhtml source code and it seems not easy to solve this problem in elegant way.

So here is my solution:

  1. Before djhtml process the HTML, we detect some special attributes and replace the value with UUID, and store the real value in a dict
  2. So some char such as > in the attribute will not be process by djhtml
  3. After djhtml process the HTML, we detect some special attributes and replace the UUID with the orignal value.

I already make it work in my Stimulus project and here is the commit michael-yin@90d5ddf

Maybe we can add attribute ignore list to djhtml and let it ignore value in the attributes.

Thx.

@JaapJoris
Copy link
Member

@michael-yin I appreciate your solution, but I think we have found an even better solution that also fixes this bug. Could you verify that the latest release solves your problem?

lb- pushed a commit to Lovelyfin00/wagtail that referenced this issue Jan 26, 2023
- Fixes formatting of `->` in Stimulus controlled element usage
- Fixes wagtail#9965
- See rtts/djhtml#57
lb- pushed a commit to wagtail/wagtail that referenced this issue Jan 26, 2023
- Fixes formatting of `->` in Stimulus controlled element usage
- Fixes #9965
- See rtts/djhtml#57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants