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 ¶
- Variables
- func FromReader(r io.Reader, opts ...Option) ([]core.Row, error)
- func FromReaderCtx(ctx context.Context, r io.Reader, opts ...Option) ([]core.Row, error)
- func FromString(htmlStr string, opts ...Option) ([]core.Row, error)
- func FromStringCtx(ctx context.Context, htmlStr string, opts ...Option) ([]core.Row, error)
- type Limits
- type Option
Constants ¶
This section is empty.
Variables ¶
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 ¶
FromReader parses HTML from an io.Reader and returns the corresponding rows.
func FromReaderCtx ¶
FromReaderCtx parses HTML from an io.Reader and returns the corresponding rows. It observes ctx before and after reading and during translation.
func FromString ¶
FromString parses an HTML string and returns the corresponding Paper rows.
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 ¶
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 ¶
WithGridSize overrides the default 12-column grid for flex quantization. Use this when the paper document was built with config.WithMaxGridSize(n).
func WithImageBaseDir ¶
WithImageBaseDir scopes <img src=...> local-file reads to a single directory. Paths that escape via ".." or absolute prefix are refused.
func WithLimits ¶
WithLimits overrides resource limits for untrusted HTML translation. Zero fields keep their safe default values.
func WithStylesheetBaseDir ¶
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 ¶
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. |