-
Notifications
You must be signed in to change notification settings - Fork 351
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
[Question] Best practice to cleanup HTML Spaghetti code #630
Comments
It's unclear what you're trying to do exactly, but sanitize-html is quite good at keeping only the tags and attributes you approve, as you can see in the documentation. If you want to do more subtle things, there are transformation features. If your needs exceed that, then you might consider using |
I came here to report a similar issue. An unclosed attribute (missing final double-quote) will cause everything from the start of that tag through to the end of the input to be stripped by // ↓ Missing double-quote
sanitize(`Hello, world. <a href="/this>this</a> is a demo of this behavior. <b>I won't be in the output!</b>`)
// => 'Hello, world. ' |
Angle brackets are not forbidden in quoted HTML attributes, and in fact this document produces the expected title on hover in Chrome:
If both the standard and actual browsers permit it then sanitize-html can't reliably detect that it is "wrong" (because it isn't, strictly speaking). Also this behavior is coming from the |
@boutell Got it. So in the case of invalid HTML (the double quote never closes anywhere), is there any way to get an error back instead of having large portions of the input stripped out? |
If you mean at the very end of the fragment, when you're absolutely sure no
closing quote is coming, it looks like htmlparser2 always tidies up at the
end by closing whatever isn't closed, and we're downstream of that. There
may or may not be htmlparser2 options that modify this behavior.
…On Wed, Oct 4, 2023 at 5:16 PM Corey Ward ***@***.***> wrote:
@boutell <https://github.com/boutell> Got it. So in the case of invalid
HTML (the double quote never closes anywhere), is there any way to get an
error back instead of having large portions of the input stripped out?
—
Reply to this email directly, view it on GitHub
<#630 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAH27N2JHIUGHYKV2FSGSLX5XGZ3AVCNFSM6AAAAAA3J2GNFOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBXGY2TGOBWG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Okay, I think we can live with that for now. Thank you! |
Question or comment
I need to cleanup a random HTML page to extract readable content. Modern website use A LOT of Spaghetti HTML. For instance :
<div> <div><div> <a href="/"> <div>Title of the site</div> </a> <div lazyload="event"><!--lazy <div class="headerPageHtml"><a href="/include/news.xml" target="_blank"><img id="socialRss" alt="access to rss" src="/asset/social/rss.png"></a></div></div></div>
In this example I don't want all the
<div>
and the formating<div><img></div>
Should I strip all the
The text was updated successfully, but these errors were encountered: