I’m using Jsoup to try to clean up pretty much all the html from a document but white list a span tag with a specific class.
I’ve got this, but obviously this ends allowing all spans with attr class
String html = "<p><strong>Lorem ipsum dolor<br /> sit amet</strong></p>"+
"<span class=\"killme\">Aenean</span> quam sem" +
"<span class=\"whitelistme\">lacinia molestie</span> nibh mattis ";
String clean = Jsoup.clean(html,
Whitelist.none()
.addTags("span")
.addAttributes("span", "class"));
Is there a way to clean all html except the <span class=”whitelistme”> ?
so my end result will be
Lorem ipsum dolor sit amet
Aenean quam sem
<span class="whitelistme">lacinia molestie</span> nibh mattis
Sticking to Jsoup solution, you can try following steps, but it is hardcode:
If you find another solution – stick to it. This is a hardcode savior from your cruel CEO.