Is there a function that converts HTML to plaintext?
Is there a "hocus-pocus" function, suitable for Android, that converts HTML to plaintext?
I am referring to a function like the clipboard conversion operation found in browsers like Internet Explorer, Firefox, etc: If you select al开发者_运维问答l rendered HTML inside the browser and copy/paste it to a text editor, you will receive (most of) the text, without any HTML tags or headers.
In a similar thread, I saw a reference to html2text but it's in Python. I am looking for an Android/Java function.
Is there something like this available or must I do this myself, using Jsoup or Jtidy?
I'd try something like:
String html = "<b>hola</b>";
String plain = Html.fromHtml(html).toString();
Using JSOUP :
String plain = new HtmlToPlainText().getPlainText(Jsoup.parse(html));
Without JSOUP:
String html= "htmltext";
String newHtml = html.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", " ").trim();
精彩评论