htmlx

package
v0.190.3 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound  = errors.New("not found")
	ErrParseURL  = errors.New("could not parse URL")
	ErrParseHTML = errors.New("could not parse HTML")
)

Functions

func CheckMediumSignals

func CheckMediumSignals(n *html.Node) int

checkMediumSignals walks the HTML tree and counts Medium-specific markers.

func CleanRedditHTML

func CleanRedditHTML(content string) string

CleanRedditHTML will remove the janky table format that some reddit posts are contained within.

func ExtractImageFromHTML

func ExtractImageFromHTML(content string) (string, string, error)

func FindAllHTMLNodes

func FindAllHTMLNodes(n *html.Node, tag string) []*html.Node

FindAllHTMLNodes returns all nodes matching the tag within n.

func FindHTMLNode

func FindHTMLNode(n *html.Node, tag string) *html.Node

FindHTMLNode does a depth-first search for the first node matching the tag.

func FindMainImage

func FindMainImage(page []byte, rawURL string) (string, error)

FindMainImage tries to find a "main" image for the page, using the readability parser.

func IsHTML

func IsHTML(s string) bool

func IsHTMLElement

func IsHTMLElement(str, tag string) bool

IsHTMLElement returns a boolean indicating whether the given string is the given HTML element.

func SanitizeHTMLString

func SanitizeHTMLString(rawStr string) (string, error)

SanitizeHTMLString will parse and re-render the given string containing HTML. In doing so, the HTML is hopefully sanitized and reformatted to be well-formed HTML.

func ToPlainText

func ToPlainText(s string) string

ToPlainText converts a HTML encoded string to plain text.

Types

type Favicon

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

Favicon is a favicon link found in <head>.

func FindFavicon

func FindFavicon(
	page []byte,
	pageURL string,
) ([]byte, string, Favicon, error)

FindFavicon tries each candidate in order and returns the first one that responds with a 2xx status and a non-empty body.

Jump to

Keyboard shortcuts

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