xhtml

package module
v0.0.0-...-62a756f Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 7 Imported by: 0

README

xhtml

Utilities for working with Go's x/net/html package.

It requires Go 1.23 and a version of x/net/html with iterators.

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

This section is empty.

Jump to

Keyboard shortcuts

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