std/htmlparse
On this page
Index
- type
NodeType - type
Attr - type
Node - type
Tree- method
Tree.render - method
Tree.render_node - method
Tree.dump
- method
- type
ParseErr- method
ParseErr.display
- method
- type
RenderErr- method
RenderErr.display
- method
- fn
parse - fn
parse_with - fn
parse_fragment - fn
parse_fragment_with - fn
escape
Types
NodeType
enum NodeType {
Error
Text
Document
Element
Comment
Doctype
Raw
} derive EqGo’s html.NodeType (without the internal scope marker).
Attr
struct Attr {
namespace: Str
key: Str
val: Str
} derive EqGo’s html.Attribute: namespace is "" except for the adjusted foreign
attributes (xlink, xml, xmlns).
Node
struct Node {
typ: NodeType
data: Str
namespace: Str
attrs: List[Attr]
parent: Int
first_child: Int
last_child: Int
prev: Int
next: Int
}Go’s html.Node: data is the tag name of an element (lower case, with the
svg camel case adjustments), the text of a text or comment node, the name of
a doctype (its public and system identifiers are the attributes public
and system). namespace is "" for html, math or svg. Tree links are
indexes into Tree.nodes, -1 for none.
Tree
struct Tree {
nodes: List[Node]
root: Int
}The result of a parse: the nodes and root, the node whose children are the
result (the document, or for a fragment the html element Go’s ParseFragment
takes its nodes from).
Tree.render
fn (t: Tree) render() -> Str ! RenderErrhtml.Render of the whole result: the children of root in order.
Tree.render_node
fn (t: Tree) render_node(n: Int) -> Str ! RenderErrhtml.Render of one node (a document renders its children).
Tree.dump
fn (t: Tree) dump() -> StrThe tree in the html5lib tree-construction format Go’s tests compare (| lines, two spaces per level, attributes sorted by key, content under a
template).
ParseErr
struct ParseErr {
msg: Str
}A parse failure: the open elements nest deeper than 512 (Go’s error and panic text), or the tokenizer’s buffer limit.
ParseErr.display
fn (e: ParseErr) display() -> StrRenderErr
struct RenderErr {
msg: Str
}A tree Render refuses: an error node, a void element with children, a doctype identifier with both quote types.
RenderErr.display
fn (e: RenderErr) display() -> StrFunctions
parse
fn parse(text: Str) -> Tree ! ParseErrhtml.Parse: the document of text (UTF-8), scripting enabled.
parse_with
fn parse_with(text: Str, scripting: Bool) -> Tree ! ParseErrhtml.ParseWithOptions with ParseOptionEnableScripting(scripting).
parse_fragment
fn parse_fragment(text: Str, context_namespace: Str, context_tag: Str) -> Tree ! ParseErrhtml.ParseFragment: text as the inner html of an element of context_tag
in context_namespace ("", math or svg); an empty tag parses a
document. The nodes are the children of the result’s root.
parse_fragment_with
fn parse_fragment_with(text: Str, context_namespace: Str, context_tag: Str, scripting: Bool) -> Tree ! ParseErrhtml.ParseFragmentWithOptions with the scripting flag.
escape
fn escape(s: Str) -> Strhtml.EscapeString as x/net’s renderer applies it: &, ', <, >, "
and carriage return as &, ', <, >, ", .