1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| public static String html2text(String input) {
return html2text(input, true);
}
public static String html2text(String input, boolean replaceBR) {
// String s = nullToBlank(input).replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*",
// " ");
if (!isValid(input))
return "";
if (!replaceBR) {
input = input.replaceAll("(?i)<br[^>]*>", "br2nl").replaceAll("\n",
"br2nl");
}
String text = Jsoup.parse(input).text();
if (!replaceBR) {
text = text.replaceAll("br2nl", "\n").trim();
}
return text;
}
|