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

Check following element before removing </li> tag (edge case) #79

Closed
sgkoishi opened this issue Feb 22, 2022 · 4 comments
Closed

Check following element before removing </li> tag (edge case) #79

sgkoishi opened this issue Feb 22, 2022 · 4 comments

Comments

@sgkoishi
Copy link
Contributor

sgkoishi commented Feb 22, 2022

Input (modified from MDN)

<p>Apollo astronauts:</p>

<ul>
    <li>Neil Armstrong</li>
    <li>Alan Bean</li>
    <li>Peter Conrad</li>
    <li>Edgar Mitchell</li>
    <li>Alan Shepard</li>
    <script> /* something here */ </script>
</ul>

Actual:

...
    <li>Edgar Mitchell
    <li>Alan Shepard
        <script> /* child of alan now! */ </script>
...

Expected:
The last </li> should be kept so that the script is still at the same level as other lis.
HTML standard allows both li, script and template inside a list, and

An li element's end tag can be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element.

Found this edge case when dealing with non-standard HTML snippets with no ol or ul: the removal of </li> makes the rest part of content as child of last li 😂

@GuillaumeGomez
Copy link
Owner

That sounds like quite the corner case. :o

I don't plan to fix this considering how much of a corner case it is but feel free to send a PR. :)

@sgkoishi
Copy link
Contributor Author

Googled several online minifiers and they all preserve the ending </li> no matter if it can be omitted - but that's kind of regression.
A hacky way is to keep </li>s first but add another pipeline later after removing white space, to remove </li> inside </li><li> | </li></ul> | </li></ol> | </li></menu> - sounds weird tho?

@GuillaumeGomez
Copy link
Owner

That sounds very weird... HTML spec overall is quite the nightmare.

@sgkoishi
Copy link
Contributor Author

True, give up. Gonna fix my malformed input data magically 😀

@sgkoishi sgkoishi closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2022
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

No branches or pull requests

2 participants