
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 0.64 KB | hits: 14 | expires: Never
Removing HTML tags except line breaks
String html = "<h1>I only want<br/>line breaks and " +
"<a href='http://stackoverflow.com'>links</a>, <i>not</i>" +
" the <b>other</b> stuff";
String sansHtml = Html.fromHtml(html).toString();
Whitelist whitelist = Whitelist.none().addTags("a", "br").addAttributes("a", "href");
String jsoupHtml = Jsoup.clean(html, whitelist);
string1.replaceAll("\<br.*?>", "[br]");
string1.replaceAll("\<a href='(.*?)'.*?>(.*?)\<.*?>", "[link='$1' desc='$2']");
string1.replaceAll("\<.*?>","");
string1.replaceAll("\[br\]", "<br\>");
string1.replaceAll("\[link='(.*?)' desc='(.*?)']", "<a href="$1">$2<\a>");