content

package
v0.0.0-...-4099bc4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const WidgetElement = "ol-widget"

Variables

View Source
var FXModule = fx.Module("content_util", fx.Provide(NewDefaultEngine))

Functions

func CollectFontFamilies

func CollectFontFamilies(content string) ([]string, error)

CollectFontFamilies returns the distinct font families used in HTML content.

func CountWordsHtml

func CountWordsHtml(html string) int32

func DefaultAllowedFontSizes

func DefaultAllowedFontSizes() []string

DefaultAllowedFontSizes is shared by chapter sanitization and the editor UI.

func FixHTML

func FixHTML(htmlSnippet string) (string, error)

func SanitizeHtml

func SanitizeHtml(html string) string

SanitizeHtml takes a string of HTML content and returns a sanitized version of it, free of potentially malicious tags and attributes.

Types

type ExpandTag

type ExpandTag interface {
	Expand(node *html.Node)
	ConfigureSanitizer(policy *bluemonday.Policy)
}

type ExpandTagFunc

type ExpandTagFunc func(node *html.Node)

ExpandTagFunc adapts a function to an ExpandTag. It is useful for small tag expanders and tests that do not need to change the sanitizer policy.

func (ExpandTagFunc) ConfigureSanitizer

func (ExpandTagFunc) ConfigureSanitizer(*bluemonday.Policy)

func (ExpandTagFunc) Expand

func (f ExpandTagFunc) Expand(node *html.Node)

type MarkupEngine

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

func NewDefaultEngine

func NewDefaultEngine() *MarkupEngine

func NewEngine

func NewEngine(options MarkupEngineOptions) *MarkupEngine

func (*MarkupEngine) Clean

func (e *MarkupEngine) Clean(value string) (processed ProcessedContentData, err error)

func (*MarkupEngine) Expand

func (e *MarkupEngine) Expand(content string) (string, error)

type MarkupEngineOptions

type MarkupEngineOptions struct {
	TagExapanders map[string]ExpandTag

	// URLFilter decides whether a URL used by markup such as links and images is
	// permitted. A nil filter leaves URL validation to the sanitizer policy.
	URLFilter func(url string) bool

	// TextColorFilter decides whether a CSS text color value is permitted. A nil
	// filter leaves text color validation to the sanitizer policy.
	TextColorFilter func(color string) bool

	// AllowedFontFamilies is the fixed set of permitted font-family CSS values.
	AllowedFontFamilies []string

	// FontFamilyFilter permits dynamic font-family values.
	FontFamilyFilter func(fontFamily string) bool

	// AllowedFontSizes is the fixed set of permitted font-size CSS values.
	AllowedFontSizes []string
}

type ProcessedContentData

type ProcessedContentData struct {
	Sanitized string
	Words     int32
	Fonts     []string
}

type WidgetRegistry

type WidgetRegistry struct {
}

func NewWidgetRegistry

func NewWidgetRegistry() *WidgetRegistry

func (*WidgetRegistry) ConfigureSanitizer

func (w *WidgetRegistry) ConfigureSanitizer(policy *bluemonday.Policy)

func (*WidgetRegistry) Expand

func (w *WidgetRegistry) Expand(node *html.Node)

Jump to

Keyboard shortcuts

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