parsetree

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: EUPL-1.2 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttributeMap

func AttributeMap(node *html.Node) map[string]string

AttributeMap returns a map of attribute key-value pairs for a given HTML node. If the HTML node is nil or the HTML node contains no attributes, an empty map is returned.

func Body

func Body(node *html.Node) *html.Node

Body returns the first occurrence of a HTML "body" element in the subtree of the given HTML node, or nil if not found.

func Children

func Children(node *html.Node) []*html.Node

Children returns a slice of child HTML nodes of the provided HTML node that are either an element or a text node. If none of the child HTML nodes satisfies this condition, an empty slice is returned.

func ChildrenFunc

func ChildrenFunc(node *html.Node, predicate func(*html.Node) bool) []*html.Node

ChildrenFunc returns a slice of child HTML nodes of the given HTML node that satisfy the given predicate. The predicate function is used to filter child HTML nodes based on the provided condition. The returned slice contains all child HTML nodes that satisfy the predicate, in the order they appear in the HTML node.

func ElementsByTagName

func ElementsByTagName(node *html.Node, tags ...string) []*html.Node

ElementsByTagName recursively returns a slice of HTML nodes with the given HTML tag name(s). If the provided HTML node is nil or if no tags are provided, an empty slice is returned.

func Head(node *html.Node) *html.Node

Head returns the first occurrence of a HTML "head" element in the subtree of the given HTML node, or nil if not found.

func HeadingLevel

func HeadingLevel(node *html.Node) (int, error)

HeadingLevel returns the HTML heading level (numeric value of "h" tag) for a given HTML heading node. If the given HTML node does not contain a valid HTML heading tag (h1, h2, ..., h6), it returns -1 and an error.

func HeadingMap

func HeadingMap() map[string]int

HeadingMap returns a map of HTML heading tags (h1, h2, ..., h6) as keys and their corresponding HTML heading levels (1, 2, ..., 6) as values.

func Headings

func Headings(node *html.Node) []*html.Node

Headings returns a slice of HTML nodes representing the HTML heading elements (h1 to h6) that are direct children of the given HTML node.

func Html

func Html(nodes ...*html.Node) (template.HTML, error)

Html returns the serialized HTML content of the given HTML node.

func IsBody

func IsBody(node *html.Node) bool

IsBody checks if the given HTML node represents the HTML "body" element.

func IsElement

func IsElement(node *html.Node) bool

IsElement checks if the given HTML node represents an element node.

func IsElementFunc

func IsElementFunc(node *html.Node, predicate func(*html.Node) bool) bool

IsElementFunc checks if the given HTML node represents an HTML element node and satisfies a custom predicate function.

func IsHead

func IsHead(node *html.Node) bool

IsHead checks if the given HTML node represents the HTML "head" element.

func IsHeading

func IsHeading(node *html.Node) bool

IsHeading checks if the given HTML node represents an HTML heading element.

func IsNil

func IsNil(node *html.Node) bool

IsNil checks if the given HTML node is nil.

func IsText

func IsText(node *html.Node) bool

IsText checks if the given HTML node represents a text node.

func New

func New(string string) (*html.Node, error)

New returns the HTML parse tree from the given HTML string.

func SiblingsUntilFunc

func SiblingsUntilFunc(node *html.Node, predicate func(*html.Node) bool) []*html.Node

SiblingsUntilFunc returns a slice of HTML nodes representing the siblings of the given HTML node, until a HTML sibling node that satisfies the provided predicate function is encountered. If the predicate function is nil or if no HTML node satisfies the condition in the predicate function, all siblings of the given HTML node are returned.

func TagName

func TagName(node *html.Node) string

TagName returns the tag name of the given HTML node. If the given HTML node is nil or does not represent an HTML element, an empty string is returned.

func Text

func Text(node *html.Node) string

Text recursively returns the rendered text content of an HTML node and its children.

Types

This section is empty.

Jump to

Keyboard shortcuts

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