parsehtml

package
v0.0.0-...-3899f8b Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package parsehtml provides utilities for parsing HTML-format library documentation, which is referenced for type information by the Python "compile" check.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InBetween

func InBetween(s, before, after string) string

InBetween returns the portion of string `s` appearing after the first occurrence of substring `before` (exclusive), assuming it exists, and before the first occurrence of substring `after` (exclusive), if it exists.

func IsText

func IsText(node Node) bool

IsText returns true if the given HTML node is a text node.

func NodeIsAll

func NodeIsAll(predicates ...NodeP) func(Node) bool

NodeIsAll returns the logical conjunction ("and") of the given predicate functions of HTML nodes.

func TrimPast

func TrimPast(s, before string) string

TrimPast returns the portion of string `s` appearing after the first occurrence of substring `before` (exclusive), assuming it exists.

func TrimSince

func TrimSince(s, after string) string

TrimSince returns the portion of string `s` appearing before the first occurrence of substring `after` (exclusive), if it exists, otherwise the entire string.

Types

type Attribute

type Attribute struct {
	*html.Attribute
}

Attribute wraps html.Attribute so we can define additional convenience methods

func (Attribute) AttributeIsMember

func (attribute Attribute) AttributeIsMember(attributes []html.Attribute) bool

AttributeIsMember returns true if the given slice of HTML attributes contains the given attribute, otherwise false.

func (Attribute) IsAttribute

func (attribute Attribute) IsAttribute(node Node) bool

IsAttribute returns true if the given HTML node has the given attribute, otherwise false.

type Node

type Node struct {
	*html.Node
}

Node wraps html.Node so we can define additional convenience methods

func (Node) FindChildNode

func (node Node) FindChildNode(predicate NodeP) Node

FindChildNode returns the first HTML child node of the given node that satisfies the given predicate function if one exists, otherwise nil.

func (Node) FindNextNode

func (node Node) FindNextNode(predicate NodeP) Node

FindNextNode returns the next HTML sibling node of the given node that satisfies the given predicate function if one exists, otherwise nil.

func (Node) FindNode

func (node Node) FindNode(predicate NodeP) Node

FindNode returns the next HTML sibling node, beginning with `node` itself, that satisfies the given predicate function if one exists, otherwise nil.

func (Node) OnEachChildNode

func (node Node) OnEachChildNode(predicate NodeP, process func(Node) error) error

OnEachChildNode executes the given process function on each HTML child node of the given node satisfying the given predicate function, stopping if an error occurs.

func (Node) Text

func (node Node) Text() string

Text returns the concatenation of the contents of all HTML text child nodes of the given node.

type NodeP

type NodeP func(Node) bool

NodeP represents a boolean predicate function on HTML nodes.

func HasClass

func HasClass(name string) NodeP

HasClass returns a NodeP function that returns true if the HTML node it is passed has a class attribute with the value of the given name, otherwise false.

func HasElementName

func HasElementName(name string) NodeP

HasElementName returns a NodeP function that returns true if the HTML node it is passed is an element node with the given name, otherwise false.

Jump to

Keyboard shortcuts

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