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

HTML formatting wraps ending block tag for no reason with nested inline elements #1041

Closed
garretwilson opened this issue Oct 10, 2016 · 3 comments

Comments

@garretwilson
Copy link

js-beautify leaves the following single HTML5 <aside> element untouched, as it should:

<aside><span class="foo">foo</span></aside>

If another inline element such as <span> is nested, it is expected that js-beautify should continue to leave the HTML touched, because nothing about the inline elements should cause newlines to be added:

<aside><span class="foo">foo <span class="bar">bar</span></span></aside>

However js-beautify incorrectly adds a newline before the </aside> end-tag:

<aside><span class="foo">foo <span class="bar">bar</span></span>
</aside>

There is no reason for such behavior; it is a bug. It can be verified merely by pasting and formatting in the main input field at http://jsbeautifier.org/ .

(Note that syntax highlighter on that page can't correctly show formatting colors for this simple sequence of elements, but that likely is a separate issue and may not relate to this bug.)

@bitwiseman
Copy link
Member

bitwiseman commented Oct 11, 2016

The syntax highlight is provided by another product, but it is also not configured for html. If you want to file an issue for that as well, that'd be cool.

This not limited to html 5 or aside elements:

<!-- before -->
<p><span class="foo">foo <span class="bar">bar</span></span></p>

<!-- after -->
<p><span class="foo">foo <span class="bar">bar</span></span>
</p>

But interestingly:

<!-- before -->
<aside><p class="foo">foo <span class="bar">bar</span></p></aside>
<p class="foo"><span class="bar">bar</span></p>

<!-- after -->
<aside>
    <p class="foo">foo <span class="bar">bar</span></p>
</aside>
<p class="foo"><span class="bar">bar</span></p>

I was going to say this is related to #841, but that second example shows that it is not. Definitely a bug.

@bitwiseman bitwiseman added this to the v1.6.5 milestone Oct 11, 2016
@bitwiseman bitwiseman modified the milestones: v1.6.5, v1.7.x Dec 19, 2016
@HookyQR
Copy link
Contributor

HookyQR commented Feb 11, 2017

This is the double span issue mentioned elsewhere. It's not actually spans fault. It's caused by unformatted tags not identifying nested tags of the same name. The outer <span> considers the first </span> to be it's closing tag. You can duplicate the problem by replacing span with output for instance.

@bitwiseman
Copy link
Member

@HookyQR - Oh. Yeah. Good catch, thanks. That'll help.

@bitwiseman bitwiseman modified the milestones: v1.7.x, v1.7.6 Jun 30, 2018
bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue Jun 30, 2018
@bitwiseman bitwiseman modified the milestones: v1.8.0-rc2, 1.8.0 Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants