#@serializer

    Convert a DOM tree back to HTML source. Also exposes plain-text extraction (to_text), an html5lib-style dump (to_test_format), and a few standalone predicates used elsewhere in the pipeline.

    The examples below are mbt check blocks and run as part of moon test serializer.

    #to_html — compact and pretty

    ///|
    test "readme serializer compact" {
    let node = @dom.element("article", children=[
    @dom.element("p", attrs={ "class": Some("intro") }, children=[
    @dom.text("Hello "),
    @dom.element("b", children=[@dom.text("MoonBit")]),
    ]),
    ])
    inspect(
    @serializer.to_html(node, pretty=false),
    content=(
    #|<article><p class="intro">Hello <b>MoonBit</b></p></article>
    ),
    )
    }

    pretty=true indents block-level elements; indent_size controls how many spaces are added per level.

    ///|
    test "readme serializer pretty" {
    let node = @dom.element("article", children=[
    @dom.element("p", children=[@dom.text("body")]),
    ])
    inspect(
    @serializer.to_html(node, pretty=true),
    content=(
    #|<article>
    #| <p>body</p>
    #|</article>
    ),
    )
    }

    #Escaping in text and attributes

    Text content gets &, <, > escaped automatically. Attribute values use the quote character you pass via quote= (default ").

    ///|
    test "readme serializer escapes" {
    let node = @dom.element("p", children=[@dom.text("a < b && c > d")])
    inspect(
    @serializer.to_html(node, pretty=false),
    content=(
    #|<p>a &lt; b &amp;&amp; c &gt; d</p>
    ),
    )
    }

    #Void elements

    Tags from the HTML5 void list never get an end tag.

    ///|
    test "readme serializer void elements" {
    let node = @dom.fragment(children=[
    @dom.element("br"),
    @dom.element("img", attrs={ "src": Some("/x.png") }),
    ])
    inspect(
    @serializer.to_html(node, pretty=false),
    content=(
    #|<br><img src="/x.png">
    ),
    )
    }

    #to_text — plain-text extraction

    ///|
    test "readme serializer to_text" {
    let node = @dom.element("p", children=[
    @dom.text("Hello "),
    @dom.element("b", children=[@dom.text("MoonBit")]),
    ])
    inspect(
    @serializer.to_text(node),
    content=(
    #|Hello MoonBit
    ),
    )
    }

    #to_test_format — html5lib-style dump

    Useful when you want to diff DOM structure rather than serialized HTML — it shows attributes and text children on their own indented lines, the format upstream html5lib fixtures use.

    ///|
    test "readme serializer to_test_format" {
    let node = @dom.element("p", attrs={ "class": Some("intro") }, children=[
    @dom.text("hi"),
    ])
    inspect(
    @serializer.to_test_format(node),
    content=(
    #|| <p>
    #|| class="intro"
    #|| "hi"
    ),
    )
    }

    HtmlContext

    pub(all) enum HtmlContext {
    Html
    JsString
    HtmlAttrValue
    Url
    } derive(Eq,
    Debug
    )

    Output context used by HTML serialization.

    Non-Html contexts escape serialized output for embedding in JavaScript strings, HTML attribute values, or URL text.

    HtmlContext::equal

    #deprecated("implicit derived-impl promotion; call the trait method directly")
    fn HtmlContext::equal(HtmlContext, HtmlContext) -> Bool

    HtmlContext::not_equal

    #deprecated("implicit derived-impl promotion; call the trait method directly")
    fn HtmlContext::not_equal(x : HtmlContext, y : HtmlContext) -> Bool

    HtmlContext::to_repr

    #deprecated("implicit derived-impl promotion; call the trait method directly")
    fn HtmlContext::to_repr(HtmlContext) ->
    Repr

    is_void_element

    fn is_void_element(name : StringView) -> Bool

    Return whether an HTML element is void and must not serialize an end tag.

    name is compared against the lowercase HTML void-element set.

    to_html

    fn to_html(node :
    Node
    , pretty? : Bool, indent_size? : Int, context? : HtmlContext, quote? : Char) -> String raise
    HtmlError

    Serialize a node as HTML.

    to_test_format

    fn to_test_format(node :
    Node
    ) -> String

    Render a deterministic tree dump intended for conformance tests.

    to_text

    fn to_text(node :
    Node
    , separator? : String, strip? : Bool, separator_blocks_only? : Bool) -> String

    Extract descendant text from a node.