How do I preserve line breaks when using jsoup to convert html to plain text?

I have the following code:

 public class NewClass {
     public String noTags(String str){
         return Jsoup.parse(str).text();
     }


     public static void main(String args[]) {
         String strings="" +
         "     

hello world


yo googlez

"; NewClass text = new NewClass(); System.out.println((text.noTags(strings))); }

And I have the result:

hello world yo googlez

But I want to break the line:

hello world
yo googlez

I have looked at jsoup's TextNode#getWholeText() but I can't figure out how to use it.

If there's a
in the markup I parse, how can I get a line break in my resulting output?

95
задан RAnders00 31 May 2016 в 18:17
поделиться