@std/data/html.ms#
Import each required symbol with import Name from "@std/data/html.ms".
HtmlAttribute Type#
An HTML attribute with its name, namespace and decoded value.
type HtmlAttribute {
name String
namespace String
value String
}HtmlAttribute.name#
Attribute name after 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 StringHtmlNode Enum#
A parsed HTML document tree with document, element, text, comment, and doctype nodes.
enum HtmlNode {
Document(children List[HtmlNode])
Element(tag String, namespace String, attributes List[HtmlAttribute], children List[HtmlNode])
Text(text String)
Comment(text String)
Doctype(name String, public_id String, system_id String)
}HtmlNode.Comment#
An HTML comment retained as a node rather than element text.
Comment(text String)HtmlNode.Doctype#
A document-type declaration retained from the parsed HTML.
Doctype(name String, public_id String, system_id String)HtmlNode.Document#
Root document node, including any elements implied by HTML tree normalization.
Document(children List[HtmlNode])HtmlNode.Element#
An element with normalized attributes and its ordered child nodes.
Element(tag String, namespace String, attributes List[HtmlAttribute], children List[HtmlNode])HtmlNode.Text#
Text node contents after HTML entity decoding and tree normalization.
Text(text String)HtmlNode.Comment.text#
Comment contents without the opening and closing comment delimiters.
text StringHtmlNode.Doctype.name#
Doctype name as normalized by the 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.
children List[HtmlNode]HtmlNode.Element.namespace#
Element namespace, svg or 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 StringHtmlOptions Type#
Limits for parse on input bytes, tree depth and node count. A field set to null
adds no limit. The defaults are a depth of 10,000 and 1,000,000 nodes, with no limit
on input bytes. A negative limit returns EINVAL, and input that exceeds a limit
returns EOVERFLOW.
type HtmlOptions {
max_bytes Int? = null
max_depth Int? = 10000
max_nodes Int? = 1000000
}HtmlOptions.max_bytes#
Maximum UTF-8 input bytes before parsing; null adds no input-size budget.
max_bytes Int? = nullHtmlOptions.max_depth#
Maximum normalized node depth; the document is depth zero and direct children depth one.
max_depth Int? = 10000HtmlOptions.max_nodes#
Maximum returned nodes, including document/text/comment/doctype and implied element nodes.
max_nodes Int? = 1000000escape 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 limits in options. The result is
the Document node.
fn parse(text String, options HtmlOptions = HtmlOptions()) Result[HtmlNode, Error] { ... }unescape Function#
Decodes HTML5 named and numeric character references in text context, once. A recognized reference may omit its semicolon; unrecognized text stays literal. Invalid numeric references become U+FFFD. It does not parse markup or normalize text.
fn unescape(text String) String { ... }