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.84k stars 353 forks source link

Removing elements with a certain class #150

Closed gcjbr closed 4 years ago

gcjbr commented 7 years ago

Let's say I have a big chunk of HTML and I only to remove all divs with the class 'test' from that text. I don't want to keep the div or its content, so I think allowedClasses wouldn't help. Instead, I need to remove it totally.

Is there a way I cn do this with sanitize-html or I'll have to rely on regex?

andpor commented 7 years ago

Maybe you can accomplish this in two passes...in first pass you replace the div tag with matching class with some other tag you invent. You add this new pseudo class to allowed tags.

In second pass you config this pseudo tag as nonTextTag and do not include it in allowed tags.

I have not tried this myself but it may work :)

stale[bot] commented 4 years 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.

abea commented 4 years ago

This should be possible with exclusiveFilter https://github.com/apostrophecms/sanitize-html/#filters