Manuscript Documentation
v0.1.0

@std/html.ms#

Import each required symbol with import Name from "@std/html.ms".

HtmlAttribute Record#

An HTML attribute, including its namespace and decoded value.

Manuscript
type HtmlAttribute:
    name: String
    namespace: String
    value: String

HtmlAttribute.name#

Local attribute name after native HTML parsing and normalization.

Manuscript
name: String

HtmlAttribute.namespace#

Attribute namespace prefix, or empty text for an unqualified attribute.

Manuscript
namespace: String

HtmlAttribute.value#

Decoded attribute contents, with character references resolved.

Manuscript
value: String

HtmlError Alternative#

Errors returned for malformed HTML or parser resource limits.

Manuscript
type HtmlError:
    case InvalidInput
    case InvalidData
    case LimitExceeded
Manuscript
impl Error for HtmlError:
    fn message() -> String:

HtmlError.InvalidData#

Input encoding or a native parser/tree conversion is invalid; HTML syntax can be recovered normally.

Manuscript
case InvalidData

HtmlError.InvalidInput#

A supplied input-byte, tree-depth or node-count budget is negative.

Manuscript
case InvalidInput

HtmlError.LimitExceeded#

Input bytes or the normalized returned tree exceed a supplied budget.

Manuscript
case LimitExceeded

HtmlError.Error.message#

Returns an HTML-prefixed diagnostic without echoing source markup.

Manuscript
fn message() -> String:

HtmlLimits Record#

Optional bounds for HTML input bytes, tree depth, and node count.

Manuscript
type HtmlLimits:
    max_bytes: Optional[Int] = none
    max_depth: Optional[Int] = none
    max_nodes: Optional[Int] = none

HtmlLimits.max_bytes#

Maximum UTF-8 input bytes before parsing; none adds no input-size budget.

Manuscript
max_bytes: Optional[Int] = none

HtmlLimits.max_depth#

Maximum normalized node depth; the document is depth zero and direct children depth one.

Manuscript
max_depth: Optional[Int] = none

HtmlLimits.max_nodes#

Maximum returned nodes, including document/text/comment/doctype and implied element nodes.

Manuscript
max_nodes: Optional[Int] = none

HtmlNode Alternative#

A parsed HTML document tree with document, element, text, comment, and doctype nodes.

Manuscript
type HtmlNode:
    case Document(children: List[HtmlNode])
    case Element(tag: String, namespace: String, attributes: List[HtmlAttribute], children: List[HtmlNode])
    case Text(text: String)
    case Comment(text: String)
    case Doctype(name: String, public_id: String, system_id: String)

HtmlNode.Comment#

An HTML comment retained as a node rather than element text.

Manuscript
case Comment(text: String)

HtmlNode.Doctype#

A document-type declaration retained from the parsed HTML.

Manuscript
case Doctype(name: String, public_id: String, system_id: String)

HtmlNode.Document#

Root document node, including any elements implied by HTML tree normalization.

Manuscript
case Document(children: List[HtmlNode])

HtmlNode.Element#

An element with normalized attributes and its ordered child nodes.

Manuscript
case Element(tag: String, namespace: String, attributes: List[HtmlAttribute], children: List[HtmlNode])

HtmlNode.Text#

Text node contents after HTML entity decoding and tree normalization.

Manuscript
case Text(text: String)

HtmlNode.Comment.text#

Comment contents without the opening and closing comment delimiters.

Manuscript
text: String

HtmlNode.Doctype.name#

Doctype name supplied by the native HTML parser.

Manuscript
name: String

HtmlNode.Doctype.public_id#

Public identifier, or empty text when no public identifier is present.

Manuscript
public_id: String

HtmlNode.Doctype.system_id#

System identifier, or empty text when no system identifier is present.

Manuscript
system_id: String

HtmlNode.Document.children#

Direct child nodes in normalized document order.

Manuscript
children: List[HtmlNode]

HtmlNode.Element.attributes#

Attributes in parser order, with decoded values and namespace information.

Manuscript
attributes: List[HtmlAttribute]

HtmlNode.Element.children#

Direct child nodes in normalized tree order; mutable list storage is retained.

Manuscript
children: List[HtmlNode]

HtmlNode.Element.namespace#

Element namespace, such as svg/math, or empty text for ordinary HTML.

Manuscript
namespace: String

HtmlNode.Element.tag#

Local element tag name produced by the HTML parser.

Manuscript
tag: String

HtmlNode.Text.text#

Unicode text belonging to this node, without surrounding markup.

Manuscript
text: String

escape Function#

Escapes text for insertion into an HTML text or quoted attribute context.

Manuscript
fn escape(text: String) -> String:

parse Function#

Parses HTML into a normalized tree and applies the supplied resource limits.

Manuscript
fn parse(text: String, limits: Optional[HtmlLimits] = none) -> Result[HtmlNode, HtmlError]:

unescape Function#

Decodes HTML5 named and numeric character references in text context, once. Recognized references can omit semicolons; unrecognized text remains literal. Does not parse markup or normalize text; invalid numeric scalars become U+FFFD.

Manuscript
fn unescape(text: String) -> String: