Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · htmlparse

Docs

std/htmlparse

On this page

Index

Types

NodeType

enum NodeType {
  Error
  Text
  Document
  Element
  Comment
  Doctype
  Raw
} derive Eq

Go’s html.NodeType (without the internal scope marker).

Source: std/htmlparse.xo:13

Attr

struct Attr {
  namespace: Str
  key: Str
  val: Str
} derive Eq

Go’s html.Attribute: namespace is "" except for the adjusted foreign attributes (xlink, xml, xmlns).

Source: std/htmlparse.xo:25

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.

Source: std/htmlparse.xo:36

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).

Source: std/htmlparse.xo:51

Tree.render

fn (t: Tree) render() -> Str ! RenderErr

html.Render of the whole result: the children of root in order.

Source: std/htmlparse.xo:84

Tree.render_node

fn (t: Tree) render_node(n: Int) -> Str ! RenderErr

html.Render of one node (a document renders its children).

Source: std/htmlparse.xo:86

Tree.dump

fn (t: Tree) dump() -> Str

The tree in the html5lib tree-construction format Go’s tests compare (| lines, two spaces per level, attributes sorted by key, content under a template).

Source: std/htmlparse.xo:90

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.

Source: std/htmlparse.xo:58

ParseErr.display

fn (e: ParseErr) display() -> Str

Source: std/htmlparse.xo:62

RenderErr

struct RenderErr {
  msg: Str
}

A tree Render refuses: an error node, a void element with children, a doctype identifier with both quote types.

Source: std/htmlparse.xo:66

RenderErr.display

fn (e: RenderErr) display() -> Str

Source: std/htmlparse.xo:70

Functions

parse

fn parse(text: Str) -> Tree ! ParseErr

html.Parse: the document of text (UTF-8), scripting enabled.

Source: std/htmlparse.xo:73

parse_with

fn parse_with(text: Str, scripting: Bool) -> Tree ! ParseErr

html.ParseWithOptions with ParseOptionEnableScripting(scripting).

Source: std/htmlparse.xo:75

parse_fragment

fn parse_fragment(text: Str, context_namespace: Str, context_tag: Str) -> Tree ! ParseErr

html.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.

Source: std/htmlparse.xo:79

parse_fragment_with

fn parse_fragment_with(text: Str, context_namespace: Str, context_tag: Str, scripting: Bool) -> Tree ! ParseErr

html.ParseFragmentWithOptions with the scripting flag.

Source: std/htmlparse.xo:81

escape

fn escape(s: Str) -> Str

html.EscapeString as x/net’s renderer applies it: &, ', <, >, " and carriage return as &amp;, &#39;, &lt;, &gt;, &#34;, &#13;.

Source: std/htmlparse.xo:94

↑ index