Я использую Jsoup для форматирования строки HTML в обычный текст. Я все еще хочу сохранить разрывы строк и игнорировать теги HTML. Но при конвертации я получаю лишние пустые строки, и это сбрасывает мою строку.
String htmlString = "<p>Hello this is a description. </p><p>I know Just checking how it looks.</p><p></p><p><code>Add a line.</code></p><p>This is a notmal line <span style="color:#F9931A">Adding orange</span></p><ul><li><p>one </p></li><li><p>two</p></li></ul>";
HtmlToPlainText convert = new HtmlToPlainText();
Document html = Jsoup.parse(htmlString,"", Parser.xmlParser());
String new = convert.getPlainText(html);
System.out.println("This is the description: " + new);
ВЫВОД:
Hello this is a description.
I know Just chekcing how it looks.
Add a line.
This is a notmal line Adding orange
* one
* two