Categorygithub.com/mdigger/htmlx
modulepackage
1.0.1
Repository: https://github.com/mdigger/htmlx.git
Documentation: pkg.go.dev

# README

htmlx

htmlx is a library which provides a set of extensions on go's golang.org/x/net/html library.

Go Reference

// parse html file
doc, err := htmlx.Load("test.html")
if err != nil {
    panic(err)
}

div := doc.Find(htmlx.ID("test"))
for _, a := range div.FindAll(htmlx.TagName("a")) {
    if href, ok := a.Attr("href"); ok {
        fmt.Println(href)
    }
}

err = div.SetHTML(`<em>no links</em>`)
if err != nil {
    panic(err)
}
fmt.Println("html:", div)

# Functions

AddAttrWord add new word to attribute value.
AttrVal returns the attribute value with the specified key name.
Class is used to select elements with a specified style class.
Find finds the first coincidence on the element, including himself, and returns it.
FindAll finds and returns all coincidences with the specified template.
FindNext finds the first siblins element.
FindPrev finds the previous siblin element.
Get loads and parses an HTML document at the specified url address.
HasAttrVal is used to find an element with a specified attribute value.
HasAttrWord returns true if the attribute value with the specified key name and specified word in value is found.
HTML returns a string with HTML representation.
ID is used to find an element with a specified unique identifier.
Load loads and parses an HTML document from the file.
New warps the representation of html.node by adding it a new functionality.
Parse returns a parsed HTML tree representation.
Remove removes the specified element from the HTML tree.
RemoveAttr removes the attribute with the specified key name.
RemoveChilds removes all child elements if they are.
Rename HTML element.
SetAttr set the new attribute value with the specified key name.
SetHTML parses an HTML fragment in the context of the current element and replaces them the child elements.
SetText replaces the text of the element to the new one.
Stats returns statistics on the text.
String returns a parsed HTML tree representation from the string.
Tag used to search for items on a tag name identifier.
Tag used to search for items on a tag name.
Text returns only a text representation, without HTML elements.
WriteText walk all the invested text nodes and records the text from them to the specified StringWriter.

# Constants

Predefined attribute names.
Predefined attribute names.

# Variables

TextIgnoreAtom specifies the list of items whose contents are ignored when working with text nodes.

# Structs

Node expands html.node with additional methods.

# Type aliases

Matcher used as synonym the functions for searching and selecting HTML elements.