简体   繁体   中英

Return Line Breaks from Jsoup.parse

I'm attempting to parse out the html tags from a Java string and that is working fine using the below Jsoup parse method. The only thing is that when I call the .text method it removes the line breaks ("\\n") tags. I want to keep those but still have the method return a String, any ideas?

 private static String stripHTML(String html) {
     return Jsoup.parse(html).text();
 }

Newlines aren't any different from spaces (or consecutive spaces or tabs) in HTML. What you pull out won't have any semantic meaning. <p> and <br />, on the other hand...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM