htfilter

package
v0.7.47 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: ISC Imports: 8 Imported by: 0

Documentation

Overview

A hypertext filter. Rewrite HTML into a safer whitelisted subset.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeText

func EscapeText(text string) string

A very basic escaper

func GetAttr

func GetAttr(node *html.Node, name string) string

Returns the value for a node attribute.

func HasClass

func HasClass(node *html.Node, class string) bool

Returns true if this node has specified class

func ImgToLink(node *html.Node) string

func ImgToText

func ImgToText(node *html.Node) string

func SetAttr

func SetAttr(node *html.Node, name string, value string)

func WriteText

func WriteText(w io.Writer, text string)

Types

type Filter

type Filter struct {
	Imager       func(node *html.Node) string
	SpanClasses  map[string]bool
	BaseURL      *url.URL
	WithLinks    bool
	FilterText   func(io.Writer, string)
	RetargetLink func(string) string
}

A filter. Imager is a function that is used to process <img> tags. It should return the HTML replacement. SpanClasses is a map of classes allowed for span tags. The zero filter is useful by itself. By default, images are replaced with text.

func (*Filter) NodeText

func (filt *Filter) NodeText(node *html.Node) string

func (*Filter) String

func (filt *Filter) String(shtml string) (template.HTML, error)

func (*Filter) TextOnly

func (filt *Filter) TextOnly(shtml string) (string, error)

Jump to

Keyboard shortcuts

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