@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.
type HtmlAttribute:
name: String
namespace: String
value: StringHtmlAttribute.name#
Local attribute name after native HTML parsing and normalization.
name: StringHtmlAttribute.namespace#
Attribute namespace prefix, or empty text for an unqualified attribute.
namespace: StringHtmlAttribute.value#
Decoded attribute contents, with character references resolved.
value: StringHtmlError Alternative#
Errors returned for malformed HTML or parser resource limits.
type HtmlError:
case InvalidInput
case InvalidData
case LimitExceededimpl Error for HtmlError:
fn message() -> String:HtmlError.InvalidData#
Input encoding or a native parser/tree conversion is invalid; HTML syntax can be recovered normally.
case InvalidDataHtmlError.InvalidInput#
A supplied input-byte, tree-depth or node-count budget is negative.
case InvalidInputHtmlError.LimitExceeded#
Input bytes or the normalized returned tree exceed a supplied budget.
case LimitExceededHtmlError.Error.message#
Returns an HTML-prefixed diagnostic without echoing source markup.
fn message() -> String:HtmlLimits Record#
Optional bounds for HTML input bytes, tree depth, and node count.
type HtmlLimits:
max_bytes: Optional[Int] = none
max_depth: Optional[Int] = none
max_nodes: Optional[Int] = noneHtmlLimits.max_bytes#
Maximum UTF-8 input bytes before parsing; none adds no input-size budget.
max_bytes: Optional[Int] = noneHtmlLimits.max_depth#
Maximum normalized node depth; the document is depth zero and direct children depth one.
max_depth: Optional[Int] = noneHtmlLimits.max_nodes#
Maximum returned nodes, including document/text/comment/doctype and implied element nodes.
max_nodes: Optional[Int] = noneHtmlNode Alternative#
A parsed HTML document tree with document, element, text, comment, and doctype nodes.
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.
case Comment(text: String)HtmlNode.Doctype#
A document-type declaration retained from the parsed HTML.
case Doctype(name: String, public_id: String, system_id: String)HtmlNode.Document#
Root document node, including any elements implied by HTML tree normalization.
case Document(children: List[HtmlNode])HtmlNode.Element#
An element with normalized attributes and its ordered child nodes.
case Element(tag: String, namespace: String, attributes: List[HtmlAttribute], children: List[HtmlNode])HtmlNode.Text#
Text node contents after HTML entity decoding and tree normalization.
case Text(text: String)HtmlNode.Comment.text#
Comment contents without the opening and closing comment delimiters.
text: StringHtmlNode.Doctype.name#
Doctype name supplied by the native HTML parser.
name: StringHtmlNode.Doctype.public_id#
Public identifier, or empty text when no public identifier is present.
public_id: StringHtmlNode.Doctype.system_id#
System identifier, or empty text when no system identifier is present.
system_id: StringHtmlNode.Document.children#
Direct child nodes in normalized document order.
children: List[HtmlNode]HtmlNode.Element.attributes#
Attributes in parser order, with decoded values and namespace information.
attributes: List[HtmlAttribute]HtmlNode.Element.children#
Direct child nodes in normalized tree order; mutable list storage is retained.
children: List[HtmlNode]HtmlNode.Element.namespace#
Element namespace, such as svg/math, or empty text for ordinary HTML.
namespace: StringHtmlNode.Element.tag#
Local element tag name produced by the HTML parser.
tag: StringHtmlNode.Text.text#
Unicode text belonging to this node, without surrounding markup.
text: Stringescape Function#
Escapes text for insertion into an HTML text or quoted attribute context.
fn escape(text: String) -> String:parse Function#
Parses HTML into a normalized tree and applies the supplied resource limits.
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.
fn unescape(text: String) -> String: