Formatting HTML Output
Parameters#
Parameter | Detail |
---|---|
boolean outline() |
Get if outline mode is enabled. Default is false. If enabled, the HTML output methods will consider all tags as block. |
Document.OutputSettings outline(boolean) |
Enable or disable HTML outline mode. |
Remarks#
Display all elements as block
By default, Jsoup will display only block-level elements with a trailing line break. Inline elements are displayed without a line break.
Given a body fragment, with inline elements:
<select name="menu">
<option value="foo">foo</option>
<option value="bar">bar</option>
</select>
Printing with Jsoup:
Document doc = Jsoup.parse(html);
System.out.println(doc.html());
Results in:
<html>
<head></head>
<body>
<select name="menu"> <option value="foo">foo</option> <option value="bar">bar</option> </select>
</body>
</html>
To display the output with each element treated as a block element, the outline
option has to be enabled on the document’s OutputSettings
.
Document doc = Jsoup.parse(html);
doc.outputSettings().outline(true);
System.out.println(doc.html());
Output
<html>
<head></head>
<body>
<select name="menu">
<option value="foo">foo</option>
<option value="bar">bar</option>
</select>
</body>
</html>