dq

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Document Query - A simple HTML Document query library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultNodeFilter added in v0.1.5

func DefaultNodeFilter(n *html.Node) bool

DefaultNodeFilter skips anchor elements with aria-label attributes (headerlink anchors commonly found on documentation sites).

func FindAll added in v0.1.5

func FindAll(root *html.Node, selector string) []*html.Node

FindAll returns all elements in the subtree matching the selector. Searches the entire subtree depth-first.

func FindDirectChild added in v0.1.5

func FindDirectChild(n *html.Node, selector string) *html.Node

FindDirectChild returns the first direct child element matching the selector, or nil if none is found. Only checks immediate children, not deeper descendants.

func FindOne added in v0.1.5

func FindOne(root *html.Node, selector string) *html.Node

FindOne returns the first element in the subtree matching the selector, or nil if none is found. Searches the entire subtree depth-first.

func GetAttr added in v0.1.5

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

GetAttr returns the value of the named attribute, or "" if not found.

func GetHref

func GetHref(n *html.Node) string

GetHref is a convenience shorthand for GetAttr(n, "href").

func HasChild

func HasChild(n *html.Node, pattern string) bool

func InnerText

func InnerText(n *html.Node, recurse bool) string

InnerText extracts text content from a node using the default filter.

func InnerTextWithFilter added in v0.1.5

func InnerTextWithFilter(n *html.Node, recurse bool, filter NodeFilter) string

InnerTextWithFilter extracts text content from a node, skipping child nodes for which filter returns false. When recurse is true, element children are recursively processed and surrounded by spaces.

func RawInnerText

func RawInnerText(n *html.Node, recurse bool) string

func Traverse

func Traverse(n *html.Node, ms []Matcher)

Types

type MatchFunc

type MatchFunc func(*html.Node) bool

func NewMatchFunc

func NewMatchFunc(pattern string) MatchFunc

type MatchHandlerFunc

type MatchHandlerFunc func(*html.Node)

type Matcher

type Matcher interface {
	Match(n *html.Node) bool
	Handler(n *html.Node)
	SubMatchers() []Matcher
}

type NodeFilter added in v0.1.5

type NodeFilter func(n *html.Node) bool

NodeFilter returns true to include a child node, false to skip it.

type NodeMatcher

type NodeMatcher struct {
	// contains filtered or unexported fields
}

func NewNodeMatcher

func NewNodeMatcher(
	matchFunc MatchFunc,
	handler MatchHandlerFunc,
	children ...Matcher,
) *NodeMatcher

func (*NodeMatcher) Handler

func (m *NodeMatcher) Handler(n *html.Node)

func (*NodeMatcher) Match

func (m *NodeMatcher) Match(n *html.Node) bool

func (*NodeMatcher) SubMatchers

func (m *NodeMatcher) SubMatchers() []Matcher

type RecursiveNodeMatcher added in v0.1.5

type RecursiveNodeMatcher struct {
	// contains filtered or unexported fields
}

RecursiveNodeMatcher handles recursive pattern matching for nested structures like "ul > li > ol > li" where the pattern can repeat at different nesting levels

func NewRecursiveNodeMatcher added in v0.1.5

func NewRecursiveNodeMatcher(
	pattern string,
	handler MatchHandlerFunc,
	recursive bool,
	children ...Matcher,
) *RecursiveNodeMatcher

NewRecursiveNodeMatcher creates a new recursive matcher pattern: space-separated pattern like "ul > li > ol > li" or "ul li ol li" handler: function to call when the full pattern matches recursive: if true, pattern restarts after completion for nested structures children: additional matchers to apply after pattern completion

func (*RecursiveNodeMatcher) Handler added in v0.1.5

func (m *RecursiveNodeMatcher) Handler(n *html.Node)

func (*RecursiveNodeMatcher) Match added in v0.1.5

func (m *RecursiveNodeMatcher) Match(n *html.Node) bool

func (*RecursiveNodeMatcher) SubMatchers added in v0.1.5

func (m *RecursiveNodeMatcher) SubMatchers() []Matcher

Jump to

Keyboard shortcuts

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