xhtml

package
v0.0.0-...-0b71a0b Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 9 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 All

func All(n *html.Node) iter.Seq[*html.Node]

All vists all child nodes in depth-first pre-order.

func AppendText

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

func Attr

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

func ChildNodes

func ChildNodes(n *html.Node) iter.Seq[*html.Node]

ChildNodes returns a seq of the immediate 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 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 IsBalanced

func IsBalanced(s string) bool

IsBalanced reports whether every opening tag has a closing pair.

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 Parents

func Parents(n *html.Node) iter.Seq[*html.Node]

Parents returns an iterator traversing the node's parents.

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 Select

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

Select returns the first child node matched by the selector or nil.

func SelectAll

func SelectAll(n *html.Node, match func(*html.Node) bool) iter.Seq[*html.Node]

SelectAll returns an iterator yielding matching nodes.

func SelectSlice

func SelectSlice(n *html.Node, match func(*html.Node) bool) []*html.Node

SelectSlice returns a slice of child nodes matched by the selector.

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) iter.Seq2[*html.Node, TableNodes]

func TextContent

func TextContent(n *html.Node) string

TextContent joins and trims the text node children of n.

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 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