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] Bad indentation #432

Closed
3 tasks done
tonial opened this issue Oct 21, 2022 · 7 comments
Closed
3 tasks done

[BUG] [Formatter] Bad indentation #432

tonial opened this issue Oct 21, 2022 · 7 comments
Labels

Comments

@tonial
Copy link

tonial commented Oct 21, 2022

System Info

  • OS: Ubuntu 22.04
  • Python Version 3.10.6
  • djLint Version 1.19.2
  • template language: django

Issue

Reformatting does work on

<p>
    <span class="badge">New</span> You can now use <strong>this feature</strong>
</p>

How To Reproduce

when using djlint --reformat myfile.html, the content becomes

<p>
    <span class="badge">New</span> You can now use <strong>this feature</strong>
    </p>

NB :

  • Without You can now use it works correctly
  • With a span instead of strong, it also works correctly

I was able to get around this issue with a breakline. The following file doesn't cause the indentation error.

<p>
    <span class="badge">New</span>
    You can now use <strong>this feature</strong>
</p>
@tonial tonial added 🦠 bug Something isn't working 🧽 formatter labels Oct 21, 2022
@tonial tonial changed the title [BUG] [Formatter] [BUG] [Formatter] Bad indentation Oct 21, 2022
@tonial
Copy link
Author

tonial commented Oct 21, 2022

I tried to look into it : in both workaround cases, when processed in indent_html() the 2nd item (starting with <span> goes in to this condition https://github.com/Riverside-Healthcare/djLint/blob/0d1f7222934a65aa71ecf259ca772bbebada66ae/src/djlint/formatter/indent.py#L68-L88

The faulty file skip this condition and end in the # if indent, move right case

I don't know if the fix should be in indent_html() to allow this kind of lines, or if expand_html() should split the line after the </span>

@christopherpickering
Copy link
Contributor

Thanks! Yep, you find the problem line, in indent_html.
Right now that regex is not allowing any trialing text/html, but it should. I can update it, or if you already have something start feel free to send it over!

@tonial
Copy link
Author

tonial commented Oct 24, 2022

Hi,
I tried do change the regex to allow it, but I'm afraid I'm not achieving much.
I'll guess I'll let you handle it 😅

@christopherpickering
Copy link
Contributor

Ok, thanks, no problem :)

@christopherpickering
Copy link
Contributor

I loosened it up a bit, now it will check:

  • line starts w/ a "single line tag"
  • has some space or stuff
  • ends with a "single line tag"
  • maybe has some whitespace.
    I think it fixes you problem and probably a few more..... Really need to get djlint changed to a parser instead of regex for stuff like this!

Thanks @tonial

@tonial
Copy link
Author

tonial commented Oct 25, 2022

That was fast !
Thanks for your work on this project !

christopherpickering pushed a commit that referenced this issue Oct 25, 2022
## [1.19.3](v1.19.2...v1.19.3) (2022-10-25)

### Bug Fixes

* **formatter:** fixed poor formatting on long inline blocks ([62a8879](62a8879)), closes [#432](#432)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.19.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants