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

Add tags #618

Closed tyzion closed 10 months ago

tyzion commented 1 year ago

Hi! I wanted to know if it was possible to create a function which adds an html tag in a desired position or inside/outside a filtered tag. I didn't find anything online or on you docs. Hope nothing slipped my search.

Anyway if this feature is not present, would it be possible to implement it?

Thanks guys!!

boutell commented 1 year ago

You can do a lot with the transformTags option, but if this doesn't meet your needs, your project might be more appropriate for the cheerio package. cheerio lets you manipulate a document server-side like jQuery would, which gives you a lot of flexibility for these use cases that go well beyond sanitization. You may wish to combine the two.

tyzion commented 1 year ago

Yeah I think I'll take a look into that, thanks!

tyzion commented 1 year ago

I used a combination of the 2 as you suggested, thank you very much! And thanks a lot for this library!! If it's out of scope, I'll close this issue

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.

ile commented 3 months ago

Or domino https://github.com/fgnass/domino (instead of cheerio).

boutell commented 3 months ago

The domino docs say it is "not intended for untrusted code," which would make me a little nervous about using it for sanitization, at least without more understanding of what they mean by that.