Milky2018/html/src does not have a README file

    Attribute

    pub struct Attribute {
    name : String
    value : String
    }

    Attribute in a start/end tag
    impl Eq for Attribute
    impl Show for Attribute

    Document

    pub struct Document {
    nodes : Array[Node]
    document_element : Int
    head_element : Int
    body_element : Int
    quirks_mode : QuirksMode
    }

    The complete document owns all nodes in a flat array
    impl Show for Document

    Document::add_node

    fn Document::add_node(self : Document, node : Node) -> Int

    Add a new node and return its ID

    Document::append_child

    fn Document::append_child(self : Document, parent_id : Int, child_id : Int) -> Unit

    Append a child node to a parent

    Document::dump

    fn Document::dump(self : Document) -> String

    Dump document in html5lib-tests format for conformance testing

    Document::get_attribute

    fn Document::get_attribute(self : Document, id : Int, attr_name : String) -> String?

    Get an attribute value from an element

    Document::get_children

    fn Document::get_children(self : Document, id : Int) -> Array[Int]

    Get children of a node

    Document::get_element

    fn Document::get_element(self : Document, id : Int) -> Element?

    Get an element by ID (returns None if not an element)

    Document::get_node

    fn Document::get_node(self : Document, id : Int) -> Node?

    Get a node by ID

    Document::get_ns

    fn Document::get_ns(self : Document, id : Int) -> Namespace?

    Get the namespace of an element node

    Document::get_parent

    fn Document::get_parent(self : Document, id : Int) -> Int

    Get the parent of a node

    Document::get_tag_name

    fn Document::get_tag_name(self : Document, id : Int) -> String?

    Get the tag name of an element node

    Document::get_template_content

    fn Document::get_template_content(self : Document, id : Int) -> Int

    Get the template content of a template element

    Document::get_text_content

    fn Document::get_text_content(self : Document, id : Int) -> String

    Get text content of a node (concatenation of all text descendants)

    Document::has_attribute

    fn Document::has_attribute(self : Document, id : Int, attr_name : String) -> Bool

    Check if an element has a specific attribute

    Document::insert_before

    fn Document::insert_before(self : Document, parent_id : Int, child_id : Int, reference_id : Int) -> Unit

    Insert a child node before another child

    Document::is_element

    fn Document::is_element(self : Document, id : Int, tag_name : String, ns : Namespace) -> Bool

    Check if a node is an element with the given tag name and namespace

    Document::is_html_element

    fn Document::is_html_element(self : Document, id : Int, tag_name : String) -> Bool

    Check if a node is an HTML element with the given tag name

    Document::new

    fn Document::new() -> Document

    Create a new empty document

    Document::remove_child

    fn Document::remove_child(self : Document, parent_id : Int, child_id : Int) -> Unit

    Remove a child from its parent

    Document::set_attribute

    fn Document::set_attribute(self : Document, id : Int, attr_name : String, attr_value : String) -> Unit

    Set an attribute on an element

    Document::to_html

    fn Document::to_html(self : Document) -> String

    Serialize document to HTML string

    Element

    pub struct Element {
    tag_name : String
    ns : Namespace
    attributes : Array[(String, String)]
    children : Array[Int]
    parent : Int
    is_html_integration_point : Bool
    is_mathml_text_integration_point : Bool
    template_content : Int
    }

    DOM Element node
    impl Show for Element

    Element::new

    fn Element::new(tag_name : String, ns : Namespace, attributes : Array[(String, String)]) -> Element

    Create a new Element

    FormattingEntry

    pub enum FormattingEntry {
    Marker
    Element(Int, String, Array[(String, String)])
    }

    Marker or Element entry in the active formatting elements list

    InsertionMode

    pub(all) enum InsertionMode {
    Initial
    BeforeHtml
    BeforeHead
    InHead
    InHeadNoscript
    AfterHead
    InBody
    Text
    InTable
    InTableText
    InCaption
    InColumnGroup
    InTableBody
    InRow
    InCell
    InSelect
    InSelectInTable
    InTemplate
    AfterBody
    InFrameset
    AfterFrameset
    AfterAfterBody
    AfterAfterFrameset
    InForeignContent
    }

    25 tree construction insertion modes (WHATWG 13.2.6)

    Namespace

    pub(all) enum Namespace {
    HTML
    SVG
    MathML
    }

    Namespace for HTML, SVG, MathML
    impl Eq for Namespace
    impl Show for Namespace

    Node

    pub enum Node {
    ElementNode(Element)
    TextNode(String)
    CommentNode(String)
    DocumentTypeNode(String, String, String)
    DocumentNode(Array[Int])
    DocumentFragmentNode(Array[Int])
    }

    DOM Node - sum type for all node kinds
    impl Show for Node

    ParseError

    pub struct ParseError {
    code : ParseErrorCode
    position : SourcePosition
    }

    A parse error with location
    impl Eq for ParseError
    impl Show for ParseError

    ParseErrorCode

    pub(all) enum ParseErrorCode {
    AbruptClosingOfEmptyComment
    EofInComment
    IncorrectlyClosedComment
    IncorrectlyOpenedComment
    NestedComment
    AbruptDoctypePublicIdentifier
    AbruptDoctypeSystemIdentifier
    EofInDoctype
    InvalidCharacterSequenceAfterDoctypeName
    MissingDoctypeName
    MissingDoctypePublicIdentifier
    MissingDoctypeSystemIdentifier
    MissingQuoteBeforeDoctypePublicIdentifier
    MissingQuoteBeforeDoctypeSystemIdentifier
    MissingWhitespaceAfterDoctypePublicKeyword
    MissingWhitespaceAfterDoctypeSystemKeyword
    MissingWhitespaceBeforeDoctypeName
    MissingWhitespaceBetweenDoctypePublicAndSystemIdentifiers
    UnexpectedCharacterAfterDoctypeSystemIdentifier
    DuplicateAttribute
    EndTagWithAttributes
    EndTagWithTrailingSolidus
    EofBeforeTagName
    EofInTag
    InvalidFirstCharacterOfTagName
    MissingAttributeValue
    MissingEndTagName
    MissingWhitespaceBetweenAttributes
    NonVoidHtmlElementStartTagWithTrailingSolidus
    UnexpectedCharacterInAttributeName
    UnexpectedCharacterInUnquotedAttributeValue
    UnexpectedEqualsSignBeforeAttributeName
    UnexpectedNullCharacter
    UnexpectedQuestionMarkInsteadOfTagName
    UnexpectedSolidusInTag
    AbsenceOfDigitsInNumericCharacterReference
    CharacterReferenceOutsideUnicodeRange
    ControlCharacterReference
    MissingSemicolonAfterCharacterReference
    NoncharacterCharacterReference
    NullCharacterReference
    SurrogateCharacterReference
    UnknownNamedCharacterReference
    CdataInHtmlContent
    ControlCharacterInInputStream
    EofInCdata
    EofInScriptHtmlCommentLikeText
    NoncharacterInInputStream
    SurrogateInInputStream
    }

    WHATWG HTML5 Parse Errors (49 types per specification)

    QuirksMode

    pub(all) enum QuirksMode {
    NoQuirks
    Quirks
    LimitedQuirks
    }

    Document quirks mode (WHATWG 3.1.4)
    impl Eq for QuirksMode
    impl Show for QuirksMode

    SourcePosition

    pub struct SourcePosition {
    line : Int
    column : Int
    offset : Int
    }

    Source position for error reporting

    StackEntry

    pub struct StackEntry {
    node_id : Int
    tag_name : String
    ns : Namespace
    }

    Entry in the stack of open elements

    State

    pub(all) enum State {
    Data
    RCDATA
    RAWTEXT
    ScriptData
    PLAINTEXT
    TagOpen
    EndTagOpen
    TagName
    SelfClosingStartTag
    RCDATALessThanSign
    RCDATAEndTagOpen
    RCDATAEndTagName
    RAWTEXTLessThanSign
    RAWTEXTEndTagOpen
    RAWTEXTEndTagName
    ScriptDataLessThanSign
    ScriptDataEndTagOpen
    ScriptDataEndTagName
    ScriptDataEscapeStart
    ScriptDataEscapeStartDash
    ScriptDataEscaped
    ScriptDataEscapedDash
    ScriptDataEscapedDashDash
    ScriptDataEscapedLessThanSign
    ScriptDataEscapedEndTagOpen
    ScriptDataEscapedEndTagName
    ScriptDataDoubleEscapeStart
    ScriptDataDoubleEscaped
    ScriptDataDoubleEscapedDash
    ScriptDataDoubleEscapedDashDash
    ScriptDataDoubleEscapedLessThanSign
    ScriptDataDoubleEscapeEnd
    BeforeAttributeName
    AttributeName
    AfterAttributeName
    BeforeAttributeValue
    AttributeValueDoubleQuoted
    AttributeValueSingleQuoted
    AttributeValueUnquoted
    AfterAttributeValueQuoted
    BogusComment
    MarkupDeclarationOpen
    CommentStart
    CommentStartDash
    Comment
    CommentLessThanSign
    CommentLessThanSignBang
    CommentLessThanSignBangDash
    CommentLessThanSignBangDashDash
    CommentEndDash
    CommentEnd
    CommentEndBang
    DOCTYPE
    BeforeDOCTYPEName
    DOCTYPEName
    AfterDOCTYPEName
    AfterDOCTYPEPublicKeyword
    BeforeDOCTYPEPublicIdentifier
    DOCTYPEPublicIdentifierDoubleQuoted
    DOCTYPEPublicIdentifierSingleQuoted
    AfterDOCTYPEPublicIdentifier
    BetweenDOCTYPEPublicAndSystemIdentifiers
    AfterDOCTYPESystemKeyword
    BeforeDOCTYPESystemIdentifier
    DOCTYPESystemIdentifierDoubleQuoted
    DOCTYPESystemIdentifierSingleQuoted
    AfterDOCTYPESystemIdentifier
    BogusDOCTYPE
    CDATASection
    CDATASectionBracket
    CDATASectionEnd
    CharacterReference
    NamedCharacterReference
    AmbiguousAmpersand
    NumericCharacterReference
    HexadecimalCharacterReferenceStart
    DecimalCharacterReferenceStart
    HexadecimalCharacterReference
    DecimalCharacterReference
    NumericCharacterReferenceEnd
    }

    All 80 WHATWG tokenizer states
    impl Eq for State
    impl Show for State

    Token

    pub(all) enum Token {
    DOCTYPE(String?, String?, String?, Bool)
    StartTag(String, Array[Attribute], Bool)
    EndTag(String)
    Character(Char)
    Comment(String)
    EOF
    }

    HTML5 Token types per WHATWG spec
    impl Eq for Token
    impl Show for Token

    Tokenizer

    pub struct Tokenizer {
    input : Array[Char]
    pos : Int
    line : Int
    column : Int
    saw_eof : Bool
    state : State
    return_state : State
    errors : Array[ParseError]
    current_tag_name : StringBuilder
    current_tag_is_end : Bool
    current_tag_self_closing : Bool
    current_attrs : Array[Attribute]
    current_attr_name : StringBuilder
    current_attr_value : StringBuilder
    current_comment : StringBuilder
    current_doctype_name : StringBuilder
    current_doctype_public_id : StringBuilder
    current_doctype_system_id : StringBuilder
    current_doctype_force_quirks : Bool
    current_doctype_public_id_set : Bool
    current_doctype_system_id_set : Bool
    char_ref_code : Int
    temp_buffer : StringBuilder
    last_start_tag_name : String
    pending_tokens : Array[Token]
    in_foreign_content : Bool
    }

    HTML5 Tokenizer per WHATWG Living Standard

    Tokenizer::get_errors

    fn Tokenizer::get_errors(self : Tokenizer) -> Array[ParseError]

    Get all parse errors

    Tokenizer::get_position

    fn Tokenizer::get_position(self : Tokenizer) -> SourcePosition

    Get current source position

    Tokenizer::new

    fn Tokenizer::new(input : String) -> Tokenizer

    Create a tokenizer from a string

    Tokenizer::next_token

    fn Tokenizer::next_token(self : Tokenizer) -> Token

    Read the next token

    Tokenizer::switch_to_plaintext

    fn Tokenizer::switch_to_plaintext(self : Tokenizer) -> Unit

    Switch tokenizer to PLAINTEXT mode (for )

    Tokenizer::switch_to_rawtext

    fn Tokenizer::switch_to_rawtext(self : Tokenizer) -> Unit

    Switch tokenizer to RAWTEXT mode (for , , etc.)

    Tokenizer::switch_to_rcdata

    fn Tokenizer::switch_to_rcdata(self : Tokenizer) -> Unit

    Switch tokenizer to RCDATA mode (for , )

    Tokenizer::switch_to_script_data

    fn Tokenizer::switch_to_script_data(self : Tokenizer) -> Unit

    Switch tokenizer to Script Data mode (for )

    TreeBuilder

    pub struct TreeBuilder {
    tokenizer : Tokenizer
    document : Document
    open_elements : Array[StackEntry]
    active_formatting : Array[FormattingEntry]
    mode : InsertionMode
    original_mode : InsertionMode
    template_modes : Array[InsertionMode]
    head_element : Int
    form_element : Int
    scripting : Bool
    frameset_ok : Bool
    foster_parenting : Bool
    pending_table_chars : Array[Char]
    skip_next_newline : Bool
    errors : Array[ParseError]
    }

    The HTML tree builder (WHATWG 13.2.6)

    TreeBuilder::acknowledge_self_closing

    fn TreeBuilder::acknowledge_self_closing(self : TreeBuilder, _token : Token) -> Unit

    Acknowledge self-closing flag (suppresses error)

    TreeBuilder::adjusted_current_node

    fn TreeBuilder::adjusted_current_node(self : TreeBuilder) -> StackEntry

    Get the adjusted current node (for fragment parsing)

    TreeBuilder::clear_active_formatting_to_marker

    fn TreeBuilder::clear_active_formatting_to_marker(self : TreeBuilder) -> Unit

    Clear active formatting elements to the last marker

    TreeBuilder::create_element_for_token

    fn TreeBuilder::create_element_for_token(self : TreeBuilder, name : String, attrs : Array[(String, String)], ns : Namespace) -> Int

    Create an element without inserting it (for adoption agency)

    TreeBuilder::current_node

    fn TreeBuilder::current_node(self : TreeBuilder) -> StackEntry

    Get the current node (last element in stack)

    TreeBuilder::emit_error

    fn TreeBuilder::emit_error(self : TreeBuilder, code : ParseErrorCode) -> Unit

    Emit a parse error

    TreeBuilder::find_formatting_element

    fn TreeBuilder::find_formatting_element(self : TreeBuilder, tag_name : String) -> FormattingEntry?

    Find a formatting element by tag name

    TreeBuilder::find_formatting_element_index

    fn TreeBuilder::find_formatting_element_index(self : TreeBuilder, tag_name : String) -> Int

    Find formatting element index in list

    TreeBuilder::find_furthest_block

    fn TreeBuilder::find_furthest_block(self : TreeBuilder, formatting_idx : Int) -> Int

    Find the furthest block from the formatting element

    TreeBuilder::generate_all_implied_end_tags

    fn TreeBuilder::generate_all_implied_end_tags(self : TreeBuilder) -> Unit

    Generate all implied end tags

    TreeBuilder::generate_implied_end_tags

    fn TreeBuilder::generate_implied_end_tags(self : TreeBuilder, except : String) -> Unit

    Generate implied end tags (except for given tag)

    TreeBuilder::generate_implied_end_tags_thoroughly

    fn TreeBuilder::generate_implied_end_tags_thoroughly(self : TreeBuilder) -> Unit

    Generate implied end tags thoroughly

    TreeBuilder::get_formatting_entry

    fn TreeBuilder::get_formatting_entry(self : TreeBuilder, idx : Int) -> FormattingEntry?

    Get the formatting element entry at an index

    TreeBuilder::has_element_in_stack

    fn TreeBuilder::has_element_in_stack(self : TreeBuilder, tag_name : String) -> Bool

    Check if the stack has an element with the given tag name

    TreeBuilder::in_button_scope

    fn TreeBuilder::in_button_scope(self : TreeBuilder, tag_name : String) -> Bool

    Check if tag is in button scope

    TreeBuilder::in_default_scope

    fn TreeBuilder::in_default_scope(self : TreeBuilder, tag_name : String) -> Bool

    Check if tag is in default scope

    TreeBuilder::in_list_item_scope

    fn TreeBuilder::in_list_item_scope(self : TreeBuilder, tag_name : String) -> Bool

    Check if tag is in list item scope

    TreeBuilder::in_scope

    fn TreeBuilder::in_scope(self : TreeBuilder, tag_name : String, scope_elements : Array[String]) -> Bool

    Check if an element with the given tag is in scope

    TreeBuilder::in_select_scope

    fn TreeBuilder::in_select_scope(self : TreeBuilder, tag_name : String) -> Bool

    Select scope - everything except optgroup and option

    TreeBuilder::in_table_scope

    fn TreeBuilder::in_table_scope(self : TreeBuilder, tag_name : String) -> Bool

    Check if tag is in table scope Table scope ONLY checks for html, table, template - NOT SVG/MathML elements

    TreeBuilder::insert_character

    fn TreeBuilder::insert_character(self : TreeBuilder, c : Char) -> Unit

    Insert a character node

    TreeBuilder::insert_character_in_node

    fn TreeBuilder::insert_character_in_node(self : TreeBuilder, parent_id : Int, c : Char) -> Unit

    Insert a character into a specific node (used by AfterBody mode)

    TreeBuilder::insert_comment

    fn TreeBuilder::insert_comment(self : TreeBuilder, text : String) -> Unit

    Insert a comment node

    TreeBuilder::insert_comment_at_document

    fn TreeBuilder::insert_comment_at_document(self : TreeBuilder, text : String) -> Unit

    Insert a comment at document level

    TreeBuilder::insert_doctype

    fn TreeBuilder::insert_doctype(self : TreeBuilder, name : String?, public_id : String?, system_id : String?) -> Unit

    Insert a DOCTYPE node

    TreeBuilder::insert_element_for_token

    fn TreeBuilder::insert_element_for_token(self : TreeBuilder, name : String, attrs : Array[Attribute], ns : Namespace) -> Int

    Create an element for a token and insert it

    TreeBuilder::insert_foreign_element

    fn TreeBuilder::insert_foreign_element(self : TreeBuilder, name : String, attrs : Array[Attribute], ns : Namespace) -> Int

    Insert a foreign element

    TreeBuilder::insert_html_element

    fn TreeBuilder::insert_html_element(self : TreeBuilder, name : String, attrs : Array[Attribute]) -> Int

    Insert an HTML element

    TreeBuilder::new

    fn TreeBuilder::new(html : String) -> TreeBuilder

    Create a new tree builder for parsing HTML

    TreeBuilder::new_with_options

    fn TreeBuilder::new_with_options(html : String, scripting~ : Bool) -> TreeBuilder

    Create a new tree builder with options

    TreeBuilder::parse

    fn TreeBuilder::parse(self : TreeBuilder) -> Document

    Parse the document and return it

    TreeBuilder::parse_rawtext

    fn TreeBuilder::parse_rawtext(self : TreeBuilder, name : String, attrs : Array[Attribute]) -> Unit

    Switch tokenizer to RAWTEXT and set up text mode parsing

    TreeBuilder::parse_rcdata

    fn TreeBuilder::parse_rcdata(self : TreeBuilder, name : String, attrs : Array[Attribute]) -> Unit

    Switch tokenizer to RCDATA and set up text mode parsing

    TreeBuilder::parse_script

    fn TreeBuilder::parse_script(self : TreeBuilder, name : String, attrs : Array[Attribute]) -> Unit

    Switch tokenizer to script data state

    TreeBuilder::pop_element

    fn TreeBuilder::pop_element(self : TreeBuilder) -> StackEntry

    Pop the current element from the stack

    TreeBuilder::pop_until

    fn TreeBuilder::pop_until(self : TreeBuilder, tag_name : String) -> Unit

    Pop elements until we find one with the given tag name (HTML namespace)

    TreeBuilder::pop_until_any

    fn TreeBuilder::pop_until_any(self : TreeBuilder, tags : Array[String]) -> Unit

    Pop elements until we find one matching any of the given tags

    TreeBuilder::push_active_formatting

    fn TreeBuilder::push_active_formatting(self : TreeBuilder, node_id : Int, tag_name : String, attrs : Array[Attribute]) -> Unit

    Push an element onto the active formatting list

    TreeBuilder::push_element

    fn TreeBuilder::push_element(self : TreeBuilder, node_id : Int, tag_name : String, ns : Namespace) -> Unit

    Push an element onto the stack

    TreeBuilder::push_formatting_marker

    fn TreeBuilder::push_formatting_marker(self : TreeBuilder) -> Unit

    Push a formatting marker onto the list

    TreeBuilder::reconstruct_active_formatting

    fn TreeBuilder::reconstruct_active_formatting(self : TreeBuilder) -> Unit

    Reconstruct the active formatting elements (WHATWG 13.2.4.3)

    TreeBuilder::remove_from_active_formatting

    fn TreeBuilder::remove_from_active_formatting(self : TreeBuilder, target_id : Int) -> Unit

    Remove an element from the active formatting list by node id

    TreeBuilder::remove_from_stack

    fn TreeBuilder::remove_from_stack(self : TreeBuilder, node_id : Int) -> Unit

    Remove an element from the stack by node id

    TreeBuilder::reset_insertion_mode

    fn TreeBuilder::reset_insertion_mode(self : TreeBuilder) -> Unit

    Reset the insertion mode appropriately

    TreeBuilder::run_adoption_agency

    fn TreeBuilder::run_adoption_agency(self : TreeBuilder, tag_name : String) -> Unit

    Run the adoption agency algorithm for a formatting element

    NO_NODE

    let NO_NODE : Int

    Node index for O(1) parent/sibling access (using Int directly) Sentinel value NO_NODE = -1 indicates "no node"

    is_formatting_element

    fn is_formatting_element(name : String) -> Bool

    Check if a tag name is a formatting element (adoption agency applies)

    lookup_entity

    fn lookup_entity(name : String) -> Array[Int]?

    Lookup a named character reference (without the leading &) Returns array of codepoints if found

    parse

    fn parse(html : String) -> Document

    Parse an HTML string and return the document

    parse_with_errors

    fn parse_with_errors(html : String) -> (Document, Array[ParseError])

    Parse an HTML string and return the document with errors

    parse_with_scripting

    fn parse_with_scripting(html : String) -> Document

    Parse an HTML string with scripting enabled

    tokenize

    fn tokenize(input : String) -> (Array[Token], Array[ParseError])

    Tokenize entire input and return all tokens

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io