-
Notifications
You must be signed in to change notification settings - Fork 356
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
Stop modification of br tag #51
Comments
|
http://w3c.github.io/html-reference/syntax.html#void-element
|
As long as htmlparser2 doesn't offer a way to sniff out whether the original tag had a / or not, sanitize-html will continue to use its internal list of void elements to decide whether to use /. But even if it did, I'm not sure I would change this. |
For large deployments that store a lot of user generated html, it is favorable to keep the data size as low as possible. |
@boutell I am having a similar issue with an image tag. It is totally breaking my functionality since I am working with innerHTML attribute which returns the html like it is in the browser's DOM. Chrome strips out self closing tags, which causes html that I pass through html-sanitize to be inconsistent with my innerHTML. Consistency is critical for me, since I am changing the html by selection indexes, and if the sanitize html changes it, indexes are offset. |
I have same issue here |
There is no support upstream in htmlparser2 for determining which syntax was used to close tags. This is unlikely to happen at least until a new, bc break version of sanitize-html that depends on a different html parser module. Which is likely eventually, because htmlparser2 is not receiving much maintenance, but it doesn't guarantee the library we choose will support this either. |
I am hitting this issue with quill. I don't think quill likes |
Hello, Thank you for this library. I'm also a user of Quill and I'd find it helpful to have an option to disable the addition of a slash for I wouldn't say "it's just cleaner", but "this is one of the possible correct solutions". For those interested in a solution to this particular problem, I've made it possible in my fork: To achieve this, define the type SelfClosingOptions = Record<string, boolean | { voidTag: boolean }>
type MyIOptions = Omit<sanitizeHtml.IOptions, 'selfClosing'> & {
selfClosing?: SelfClosingOptions | string[] | undefined
}
const sanitizationOptions: MyIOptions = {
allowedTags: ['p', 'strong', 'em', 'u', 's', 'blockquote', 'ul', 'ol', 'li', 'br'],
allowedAttributes: {},
selfClosing: {
br: {
voidTag: true
}
},
}
const cleaned = sanitizeHtml(
value,
sanitizationOptions as sanitizeHtml.IOptions
) |
These are really two separate features:
We can't easily do this because of the way the upstream module gives us the information.
Sure, that would be fine as long as the default doesn't change unexpectedly. @gastonyte would you like to create a PR for your feature? |
Hi @boutell, I didn't know if this feature was wanted or not, so I just made the modification in a fork to be able to use it in my app, but if it's something you would like to see integrated into your library, it is with pleasure that I will create the PR =) |
Yes, supporting this via a flag sounds great! My objection was to the original request in which the original presence or absence of a |
When I pass
<br>
through thesanitizeHtml()
is there any way to keep it from changing to<br />
?Or for other tags that may be similiar..
Thanks!
The text was updated successfully, but these errors were encountered: