xhtml

package
v0.0.0-...-16adccd Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package xhtml makes x/net/html easier

Index

Constants

This section is empty.

Variables

View Source
var WithBody = WithAtom(atom.Body)

Functions

func AdoptChildren

func AdoptChildren(dst, src *html.Node)

func AppendText

func AppendText(n *html.Node, text string)

func Attr

func Attr(n *html.Node, name string) string

func Children

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

Children returns a slice containing the children of n.

func Clone

func Clone(n *html.Node) *html.Node

Clone n and all of its children.

func Closest

func Closest(n *html.Node, match func(*html.Node) bool) *html.Node

Closest traverses the node and its parents until it finds a node that matches.

func DeleteAttr

func DeleteAttr(n *html.Node, key string)

func Find

func Find(n *html.Node, match func(*html.Node) bool) *html.Node

Find returns the first matching child node or nil.

func FindAll

func FindAll(root *html.Node, match func(*html.Node) bool) []*html.Node

FindAll returns a slice of matching nodes.

func InnerHTML

func InnerHTML(n *html.Node) string

InnerHTML returns the serialized markup contained within n.

func InnerHTMLBlocks

func InnerHTMLBlocks(n *html.Node) string

InnerHTMLBlocks is the same as InnerHTML, but it separates top level nodes with a line break.

func InnerText

func InnerText(n *html.Node) string

InnerText joins and trims the text node children of n.

func LastChildOrNew

func LastChildOrNew(p *html.Node, tag string, attrs ...string) *html.Node

func Map

func Map[T any](tbl TableNodes, f func(*html.Node) T) [][]T

func New

func New(tag string, attrs ...string) *html.Node

func OuterHTML

func OuterHTML(n *html.Node) string

OuterHTML returns a serialized node.

func RemoveAll

func RemoveAll(nodes []*html.Node)

RemoveAll orphans the nodes it is passed. It ignores a node if the node is nil or already an orphan.

func ReplaceWith

func ReplaceWith(old, new *html.Node)

func SetAttr

func SetAttr(n *html.Node, key, value string)

func SetInnerHTML

func SetInnerHTML(n *html.Node, s string) error

func Tables

func Tables(root *html.Node, f func(tbl *html.Node, rows TableNodes))

func ToBuffer

func ToBuffer(n *html.Node) *bytes.Buffer

ToBuffer returns a *bytes.Buffer containing the outerHTML of n.

func UnnestChildren

func UnnestChildren(n *html.Node)

UnnestChildren has all of the children of node adopted by its parent, and then it removes the node.

func VisitAll

func VisitAll(n *html.Node, callback func(*html.Node))

VisitAll vists child nodes in depth-first pre-order.

func WithAtom

func WithAtom(a atom.Atom) func(n *html.Node) bool

Types

type TableNodes

type TableNodes [][]*html.Node

func (TableNodes) At

func (rows TableNodes) At(row, col int) *html.Node

func (TableNodes) Label

func (rows TableNodes) Label() string

func (TableNodes) Value

func (rows TableNodes) Value(name string) *html.Node

Jump to

Keyboard shortcuts

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