Jsoup

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#

Jsoup 1.9.2 API

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>

Source: https://stackoverflow.com/q/38855874/1176178


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow