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

Option to merge subsequent tags that are the same #564

Closed mustafa0x closed 1 year ago

mustafa0x commented 1 year ago

The problem to solve

Given <span>Hello</span> <span>World</span> or <b>Hello</b> <b>World</b> it would be nice to optionally merge the tags, so the above becomes <b>Hello World</b>.

Alternatives

Possible with regex, but not that robust.

boutell commented 1 year ago

This kind of thing is probably better done with cheerio. sanitize-html's scope doesn't extend to building a tree representation of the document.