Convert HTML to plain text in Java

前端 未结 6 2544
终归单人心
终归单人心 2021-02-20 08:51

I need to convert HTML to plain text. My only requirement of formatting is to retain new lines in the plain text. New lines should be displayed not only in the case of <

6条回答
  •  臣服心动
    2021-02-20 09:08

    JSoup is not FreeMarker (or any other customer/non-HTML tag) compatible. Consider this as the most pure solution for converting Html to plain text.

    http://stackoverflow.com/questions/1518675/open-source-java-library-for-html-to-text-conversion/1519726#1519726 My code:

    return new net.htmlparser.jericho.Source(html).getRenderer().setMaxLineLength(Integer.MAX_VALUE).setNewLine(null).toString();
    

提交回复
热议问题