h5

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2012 License: Artistic-2.0 Imports: 5 Imported by: 3

Documentation

Overview

Package h5 implements an html5 parser for the go language.

p := h5.NewParser(rdr)
err := p.Parse()
tree := p.Tree()

tree.Walk(func(n *Node) {
   // do something with the node
})

tree2 := tree.Clone()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Name  string
	Value string
	// contains filtered or unexported fields
}

The type of a html5 nodes attributes

func (*Attribute) Clone

func (a *Attribute) Clone() *Attribute

Clone an html5 attribute

func (*Attribute) String

func (a *Attribute) String() string

Serialize an html5 attribute to a string

type Node

type Node struct {
	Type NodeType // The type of node this is.

	Attr       []*Attribute // The attributes of the html5 node
	Parent     *Node        // The parent of the html5 node if it has one, nil otherwise
	Children   []*Node      // The children of the html5 node if it has any.
	Public     bool         // True if this is a PUBLIC doctype node
	System     bool         // True if this is a SYSTEM doctype node
	Identifier []rune       // The identifier if this is a doctype node
	// contains filtered or unexported fields
}

The type of an html5 node

func Text

func Text(str string) *Node

Construct a TextNode

func (*Node) Clone

func (n *Node) Clone() *Node

Clone an html5 nodetree to get a copy.

func (*Node) Data

func (n *Node) Data() string

String form of an html nodes data. (eg: The Tagname for ElementNodes or text for TextNodes)

func (*Node) SetData

func (n *Node) SetData(rs []rune)

Sets a Nodes data. (eg: The Tagname for ElementNodes or text for TextNodes)

func (*Node) String

func (n *Node) String() string

Serialize an html5 node to a string.

func (*Node) Walk

func (n *Node) Walk(f func(*Node))

Walk a Node tree with a given function.

type NodeType

type NodeType int

Represents the type of an html5 node

const (
	TextNode    NodeType = iota // zero value so the default
	ElementNode NodeType = iota
	DoctypeNode NodeType = iota
	CommentNode NodeType = iota
)

type ParseError

type ParseError struct {
	// contains filtered or unexported fields
}

Represents an html5 parsing error. holds a message and the current html5 node when the error occured.

func NewParseError

func NewParseError(n *Node, msg string, args ...interface{}) *ParseError

Constructor for an html5 parsing error

func (ParseError) Error

func (e ParseError) Error() string

Represent the parse error as a string

type Parser

type Parser struct {
	In  *bufio.Reader
	Top *Node

	Mode insertionMode
	// contains filtered or unexported fields
}

An html5 parsing struct. It holds the parsing state for the html5 parsing state machine.

func NewParser

func NewParser(r io.Reader) *Parser

Construct a new h5 parser from a io.Reader

func NewParserFromString

func NewParserFromString(s string) *Parser

Construct a new h5 parser from a string

func (*Parser) Parse

func (p *Parser) Parse() error

Parse an html stream. Returns an os.Error if there was problem parsing the stream. The result of parsing can be retrieved with p.Tree()

func (*Parser) Tree

func (p *Parser) Tree() *Node

Return the parsed html5 tree or nil if parsing hasn't occured yet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL