htmlutils

package
v0.0.0-...-69560be Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindNodeByID

func FindNodeByID(node *html.Node, id string, maxDepth int) *html.Node

FindNodeByID searches the tree rooted at "node" for a node with the "id" attribute with the specified value. Returns the node, or nil if no such node is found.

func GetAttr

func GetAttr(attributes []html.Attribute, attrName string) string

GetAttr returns the value for an attribute, or "" if no such attribute is present.

func GetAttrMap

func GetAttrMap(attributes []html.Attribute) map[string]string

GetAttrMap returns a map of attributes by name.

func GetNodeTextContent

func GetNodeTextContent(node *html.Node) string

GetNodeTextContent returns the text content of a node.

func GetNumericAttrFromMapWithDefault

func GetNumericAttrFromMapWithDefault(attrMap map[string]string, attrName string, def int64) int64

GetNumericAttrFromMapWithDefault parses an attribute to a number, and returns the value, or returns `def` if the value is not present or cannot be parsed.

func HasClass

func HasClass(attributes []html.Attribute, className string) bool

HasClass returns true if the given element has the specified class.

func ResolveURL

func ResolveURL(baseURL *url.URL, relativeURL string) string

ResolveURL resolves a URL relative to a parsed URL. For example, calling `ResolveURL("http://foo.com/bar", "../baz")` would return "http://foo.com/baz".

func SkipTokenContents

func SkipTokenContents(tokenizer *html.Tokenizer, tokenType string) error

SkipTokenContents can be used when encountering a `html.StartTagToken` to read up until the matching `html.EndTagToken`, discarding everything in the middle.

func WalkNodesPreOrder

func WalkNodesPreOrder(node *html.Node, walker func(*html.Node) bool)

WalkNodesPreOrder calls `walker` on each node in pre-order. If `walker` returns false, the the given node's children will be skipped.

Types

This section is empty.

Jump to

Keyboard shortcuts

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