dom

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Copyright 2022 Hal Canary Use of this program is governed by the file LICENSE.

This is a lightweight wrapper around x/net/html, providing some extra functionality.

Index

Constants

View Source
const (
	ElementNode = html.ElementNode
	TextNode    = html.TextNode
)

Variables

This section is empty.

Functions

func ExtractText

func ExtractText(root *Node) string

Extract and combine all Text Nodes under given node.

func GetAttribute

func GetAttribute(node *Node, key string) string

Find the matching attributes, ignoring namespace.

func RenderHTML

func RenderHTML(root *Node, w io.Writer) error

Generates HTML5 doc.

func RenderHTMLExperimental

func RenderHTMLExperimental(root *Node, w io.Writer) error

Generates HTML5 doc.

func RenderXHTMLDoc

func RenderXHTMLDoc(root *Node, w io.Writer) error

Generates XHTML1 doc.

func TextBytes added in v0.1.2

func TextBytes(root *Node) int

Return the approximate number of bytes that `ExtractText` would return.

Types

type Attr

type Attr = map[string]string

type Attribute

type Attribute = html.Attribute

type Node

type Node = html.Node

func AddAttribute

func AddAttribute(node *Node, k, v string) *Node

Add an attribute to an element node, returning the node.

func Append

func Append(node *Node, children ...*Node) *Node

Append children to the node, returning the node.

func Comment

func Comment(data string) *Node

Return a HTML comment with the given data.

func Elem

func Elem(tag string, children ...*Node) *Node

Return an element with the given children.

func Element

func Element(tag string, attributes Attr, children ...*Node) *Node

Return an element with given attributes and children.

func FindNodeByAttribute

func FindNodeByAttribute(node *Node, key, value string) *Node

Return the first matching node with key attribude set to value.

func FindNodeById

func FindNodeById(node *Node, id string) *Node

Return the first matching node with `id` attribude set to id.

func FindNodeByTag

func FindNodeByTag(node *Node, tag string) *Node

Return the first matching node

func FindNodeByTagAndAttrib

func FindNodeByTagAndAttrib(root *Node, tag, key, value string) *Node

Return the first matching node. If tag is "", match key="value". If key is "", match on tag.

func FindNodeByTagAndAttribRe added in v1.1.0

func FindNodeByTagAndAttribRe(root *Node, tag, key string, value *regexp.Regexp) *Node

Return the first matching node. If tag is "", match key="value". If key is "", match on tag.

func FindNodesByTagAndAttrib

func FindNodesByTagAndAttrib(root *Node, tag, key, value string) []*Node

Return all matching nodes. If tag is "", match key="value". If key is "", match on tag.

func FindNodesByTagAndAttribRe added in v1.2.0

func FindNodesByTagAndAttribRe(root *Node, tag, key string, value *regexp.Regexp) []*Node

func Parse

func Parse(source io.Reader) (*Node, error)

Wrapper for html.Parse.

func ParseFragment added in v0.1.5

func ParseFragment(source io.Reader, context *Node) ([]*Node, error)

Wrapper for html.ParseFragment.

func RawHtml

func RawHtml(data string) *Node

Return a Node with the given raw html.

func Remove

func Remove(node *Node) *Node

Remove a node from its parent.

func Text

func Text(data string) *Node

Return a HTML node with the given text.

Jump to

Keyboard shortcuts

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