apostrophecms / sanitize-html

Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance
MIT License
3.68k stars 349 forks source link

Applying styles to allowed class #602

Closed jdozierezell closed 1 year ago

jdozierezell commented 1 year ago

I'm trying to use sanitize-html on an input field but need to allow certain classes to be entered and to have their styles applied after sanitization. I'm using Astro, and simply including the class within the scoped style tag isn't working. My guess is that the scoping is messing with things. Is there a way to apply a style within the sanitize function, perhaps within transformTags? I've looked through the docs and only see an implementation for elements, so I'm wondering if this is possible. I'm using Node v19.2.0 on MacOS X

BoDonkey commented 1 year ago

It sounds to me like you are asking for two separate things. Santize is great for making sure that HTML is well formed and can transform the input HTML automatically. It sounds like you want to take the additional step of using the sanitized input. This sounds more like a case for JavaScript manipulation of the DOM, or... Maybe I'm wrong and you can add some additional details.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.