Reputation: 14863
When I parse this one-line html and convert it back
Jsoup.parse("h<span class='cool'>un</span>d", "").body().html()
I get an extra newline after th 'h'
"h\n<span class=\"cool\">un</span>d"
How could I avoid this from happening? Because it adds an extra space when showing in a browser.
Upvotes: 2
Views: 710
Reputation: 2246
You can disable pretty print on Document by setting doc.outputSettings().prettyPrint(false)
:
@Test
public void testPrettyPrint() {
String html = "h<span class='cool'>un</span>d";
Document doc = Jsoup.parse(html, "");
System.out.println(doc.body().html());
System.out.println("==================");
doc.outputSettings().prettyPrint(false);
System.out.println(doc.body().html());
}
Result:
h
<span class="cool">un</span>d
==================
h<span class="cool">un</span>d
Upvotes: 2