On this page:
read
write
from_  string
from_  bytes
to_  string
to_  bytes
Newline  Mode
Newline  Mode.none
Newline  Mode.safe
Newline  Mode.pretty
0.45+9.1

2 Reading and Writing HTML🔗ℹ

function

fun html.read(

  ~in: inp :: Port.Input = Port.Input.current(),

) :: html.Document

 

function

fun html.write(

  content :: html.Document || html.Content,

  ~out: outp :: Port.Output = Port.Output.current(),

  ~newlines: newlines :: html.NewlineMode = #'safe

) :: Void

Reads an HTML document into an html.Document object or writes an html.Document or html.Content object as an HTML document. Supplying html.Content to html.write is a shortcut for supplying a document that contains just the content.

By default, html.write add newlines in a way that cannot change the meaning of the HTML document: by placing newlines just before the ending > of some closing tags. See html.NewlineMode for details.

function

fun html.from_string(str :: String) :: html.Document

 

function

fun html.from_bytes(bstr :: Bytes) :: html.Document

 

function

fun html.to_string(

  doc :: html.Document || html.Content,

  ~newlines: newlines :: html.NewlineMode = #'safe

) :: String

 

function

fun html.to_bytes(

  doc :: html.Document || html.Content,

  ~newlines: newlines :: html.NewlineMode = #'safe

) :: Bytes

Shortcuts for html.read and html.write to read or write HTML documents as strings or byte strings.

enumeration

enum html.NewlineMode

| none

| safe

| pretty

Newline-insertion modes for html.write:

  • #'none: No extra newlines are added.

  • #'safe: Newlines are added to the closing tag of some elements, just before the ending >. This newline will always be ignored when the generated HTML format is parsed again. A newline is added only for elements using one of the names in {"head", "body", "meta", "script", "td", "tr", "div", "li", "h1", "h2", "h3", "h4", "h5", "h6"}.

  • #'pretty: Newlines are added between elements where it is expected to not change the rendering of the document, but this expectation is potentially wrong depending on CSS styling. A newline is added between immediate elements in a "head" element, a newline is added between elements that have the same name among the names in {"td", "tr", "div", "li"}, and a newline is added at the end of the document.