marianoguerra/html/ast does not have a README file

    AttrName

    pub(all) struct AttrName {
    prefix : String?
    name : String
    } derive(Eq,
    Debug
    )

    xlink:href is prefix = Some("xlink"). The prefix is kept unresolved: resolving it needs the xmlns declarations in scope, which is a document question and not a markup one.

    AttrName::plain

    fn AttrName::plain(name : String) -> AttrName

    AttrName::text

    fn AttrName::text(self : AttrName) -> String

    The written form of an attribute name, prefix and all.

    AttrValue

    pub(all) enum AttrValue {
    Empty
    Value(String, String?)
    } derive(Eq,
    Debug
    )

    Empty is disabled; Value("", ..) is disabled="".

    The two are identical to a browser and different to a person reading a diff, so the tree keeps the distinction and the printer decides what to do with it. Quoting style is deliberately NOT kept: Pretty always double-quotes and Minified drops the quotes where that is legal, the same way the CSS printer normalises 'x' to "x".

    AttrValue::text

    fn AttrValue::text(self : AttrValue) -> String

    The decoded text of a value, with Empty reading as "".

    Attribute

    pub(all) struct Attribute {
    name : AttrName
    value : AttrValue
    span :
    Span

    } derive(Eq,
    Debug
    )

    Bogus

    What could not be parsed, kept so that the tree covers the whole source.

    text is the exact source the node replaced. Keeping it is what lets the printer echo an unparsable region verbatim instead of deleting it -- a page with one templating directive the parser has never seen should come back with that directive still in it.

    Closing

    pub(all) enum Closing {
    Explicit
    SelfClosing
    Void
    Implied
    Unclosed
    } derive(Eq,
    Debug
    )

    How an element ended.

    You cannot print an element back without knowing this, and no other field can be made to say it. It is the same argument LayerRule::body makes on the CSS side: the alternatives are different constructs, not one construct with an optional part.

    Comment

    pub(all) struct Comment {
    text : String
    span :
    Span

    } derive(Eq,
    Debug
    )

    A <!-- ... -->. text is the body, without the delimiters.

    Comments are first-class nodes rather than trivia attached to a neighbour. Conditional comments, <!-- /ko --> and every framework that hides a directive in one depend on it, and the CSS module's decision to drop them through the notation is the one lossy spot this module does not repeat.

    Doctype

    pub(all) struct Doctype {
    name : String
    public_id : String?
    system_id : String?
    span :
    Span

    } derive(Eq,
    Debug
    )

    A <!DOCTYPE html>, or a legacy one with its identifiers.

    Document

    pub(all) struct Document {
    children : Array[Node]
    span :
    Span

    } derive(Eq,
    Debug
    )

    A document, or a fragment: the same type.

    One type rather than two, because a fragment is a document whose children happen not to include a doctype, and every operation either would support is the same operation. html5ever needs the distinction because its tree builder runs different insertion modes for the two; a markup parser has no insertion modes to run.

    Element

    pub(all) struct Element {
    name : TagName
    attrs : Array[Attribute]
    children : Array[Node]
    closing : Closing
    span :
    Span

    name_span :
    Span

    } derive(Eq,
    Debug
    )

    Namespace

    pub(all) enum Namespace {
    Html
    Svg
    MathMl
    Other(String)
    } derive(Eq,
    Debug
    )

    Which vocabulary a name is drawn from.

    Not decoration: it decides four things that are otherwise ambiguous in the same bytes -- whether /> closes an element or is ignored, whether an attribute name is lowercased or table-adjusted, whether <![CDATA[ is CDATA or a bogus comment, and whether <title> holds text or elements.

    Node

    pub(all) enum Node {
    Element(Element)
    Text(Text)
    RawText(RawText)
    Comment(Comment)
    Doctype(Doctype)
    Cdata(String,
    Span
    )
    Bogus(Bogus)
    } derive(Eq,
    Debug
    )

    Node::children

    fn Node::children(self : Node) -> Array[Node]

    The children of a node, empty for everything that cannot have any.

    A total function rather than an option, because every caller that walks a tree wants to recurse without asking first, and "a text node has no children" is not a case worth making them handle.

    Node::span

    The span of any node, for a caller assembling a parent's.

    RawText

    pub(all) struct RawText {
    text : String
    span :
    Span

    } derive(Eq,
    Debug
    )

    The body of a script or a style.

    A separate node from Text because it is not text: no reference resolves in it, nothing in it is escaped on the way out, and the printer must refuse to emit a body containing the element's own end tag rather than escaping it, because there is no escape.

    TagName

    pub(all) struct TagName {
    ns : Namespace
    name : String
    } derive(Eq,
    Debug
    )

    An element's name: a namespace and a local name.

    The name is NORMALISED -- ASCII-lowercased in HTML, case-adjusted by table in SVG and MathML -- so that <DIV> and <div> are one node, and <LINEARGRADIENT> and <linearGradient> are the one that exists. Case is not a semantic difference in either vocabulary, which is why this normalises where Text::raw preserves.

    TagName::html

    fn TagName::html(name : String) -> TagName

    Text

    pub(all) struct Text {
    text : String
    raw : String?
    span :
    Span

    } derive(Eq,
    Debug
    )

    A run of character data, decoded.

    raw is the source spelling, kept when decoding was not the identity. It exists for the reason Number::repr exists in the CSS tree: a formatter asked to reindent a file must not also rewrite every entity in it, and turning &nbsp; into an invisible byte is a change a reviewer cannot see and a reader cannot undo.

    Text::new

    fn Text::new(text : String, raw? : String?, span? :
    Span
    ) -> Text

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io