html

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package html converts HTML strings into Paper rows so they can be added to a Paper document. No browser, no external binary, no JavaScript.

Supported tags and CSS properties are documented in docs/html-support.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrImageTooLarge is returned when an HTML image exceeds configured byte
	// or pixel limits.
	ErrImageTooLarge = htmllimits.ErrImageTooLarge

	// ErrDOMTooDeep is returned when the parsed DOM exceeds MaxDOMDepth.
	ErrDOMTooDeep = htmllimits.ErrDOMTooDeep

	// ErrDOMTooLarge is returned when the parsed DOM exceeds MaxDOMNodes.
	ErrDOMTooLarge = htmllimits.ErrDOMTooLarge

	// ErrSVGTooLarge is returned when SVG rasterization exceeds MaxSVGPixels.
	ErrSVGTooLarge = htmllimits.ErrSVGTooLarge

	// ErrStyleRulesTooLarge is returned when CSS parsing exceeds MaxStyleRules.
	ErrStyleRulesTooLarge = htmllimits.ErrStyleRulesTooLarge
)

Functions

func FromReader

func FromReader(r io.Reader, opts ...Option) ([]core.Row, error)

FromReader parses HTML from an io.Reader and returns the corresponding rows.

func FromReaderCtx

func FromReaderCtx(ctx context.Context, r io.Reader, opts ...Option) ([]core.Row, error)

FromReaderCtx parses HTML from an io.Reader and returns the corresponding rows. It observes ctx before and after reading and during translation.

func FromString

func FromString(htmlStr string, opts ...Option) ([]core.Row, error)

FromString parses an HTML string and returns the corresponding Paper rows.

func FromStringCtx

func FromStringCtx(ctx context.Context, htmlStr string, opts ...Option) ([]core.Row, error)

FromStringCtx parses an HTML string and returns the corresponding Paper rows. It observes ctx before and after DOM parsing and during translation.

Types

type Limits

type Limits = htmllimits.Limits

Limits caps resource use while translating untrusted HTML.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns the safe resource limits used by FromString and FromReader unless overridden.

type Option

type Option func(*config)

Option configures FromString / FromReader behaviour.

func WithContentWidth

func WithContentWidth(mm float64) Option

WithContentWidth sets the page content width in mm for accurate gap-to-col approximation. Default is 170mm (A4 with 20mm left+right margins).

func WithGridSize

func WithGridSize(n int) Option

WithGridSize overrides the default 12-column grid for flex quantization. Use this when the paper document was built with config.WithMaxGridSize(n).

func WithImageBaseDir

func WithImageBaseDir(dir string) Option

WithImageBaseDir scopes <img src=...> local-file reads to a single directory. Paths that escape via ".." or absolute prefix are refused.

func WithLimits

func WithLimits(l Limits) Option

WithLimits overrides resource limits for untrusted HTML translation. Zero fields keep their safe default values.

func WithStylesheetBaseDir

func WithStylesheetBaseDir(dir string) Option

WithStylesheetBaseDir scopes <link href=...> local-file reads to a single directory. Paths that escape via ".." or absolute prefix are refused.

func WithUnsafeNoLimits

func WithUnsafeNoLimits() Option

WithUnsafeNoLimits disables resource caps. Use only for trusted input.

func WithUnsupportedHandler

func WithUnsupportedHandler(fn func(thing, value string)) Option

WithUnsupportedHandler registers a callback invoked for unsupported HTML tags or CSS properties. Use it to log diagnostics during development.

Directories

Path Synopsis
Package dom provides a Paper-friendly wrapper over golang.org/x/net/html.
Package dom provides a Paper-friendly wrapper over golang.org/x/net/html.
Package translate — flex layout dispatch and item-content construction.
Package translate — flex layout dispatch and item-content construction.

Jump to

Keyboard shortcuts

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