Here you can find the source of keepLineBreak(Document docRes)
public static String keepLineBreak(Document docRes)
//package com.java2s; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.safety.Whitelist; public class Main { public static String keepLineBreak(Document docRes) { docRes.outputSettings(new Document.OutputSettings().prettyPrint(false));// makes html() preserve linebreaks and spacing docRes.select("br").append("\\n"); docRes.select("p").prepend("\\n\\n"); String result = docRes.html().replaceAll("\\\\n", "\n"); result = Jsoup.clean(result, "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false)); return result; }/*from ww w. j a v a 2s. c o m*/ }