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(ctx context.Context, r io.Reader, opts ...Option) ([]core.Row, error)
- func FromString(ctx context.Context, htmlStr string, opts ...Option) ([]core.Row, error)
- type Document
- type Limits
- type Option
- func WithContentWidth(mm float64) Option
- func WithGridSize(n int) Option
- func WithImageBaseDir(dir string) Option
- func WithLimits(l Limits) Option
- func WithOutlineFromHeadings() Option
- func WithStylesheetBaseDir(dir string) Option
- func WithUnsafeNoLimits() Option
- func WithUnsupportedHandler(fn func(thing, value string)) Option
- type PageOptions
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. It observes ctx before and after reading and during translation.
Types ¶
type Document ¶ added in v0.2.0
Document is the full result of converting an HTML document: content rows plus document-level options parsed from `@page` rules.
func DocumentFromReader ¶ added in v0.2.0
DocumentFromReader parses HTML from an io.Reader and returns the full Document result. It observes ctx before and after reading and during translation.
func DocumentFromString ¶ added in v0.2.0
DocumentFromString parses an HTML string and returns the full Document result. Unlike FromString, it surfaces `@page` size/margin options so callers (notably paper.FromHTML) can configure the page before rendering. It observes ctx before and after DOM parsing and during translation.
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 WithOutlineFromHeadings ¶ added in v0.2.0
func WithOutlineFromHeadings() Option
WithOutlineFromHeadings adds h1-h6 headings to the PDF document outline: h1 becomes a level-0 entry, h2 a level-1 entry, and so on. Hidden headings are skipped.
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.
type PageOptions ¶ added in v0.2.0
type PageOptions = translate.PageOptions
PageOptions captures the supported subset of the CSS `@page` rule.
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. |