Documentation
¶
Overview ¶
Package translate — flex layout dispatch and item-content construction. Quantization, weight computation, and slack distribution live in flex_layout.go.
Package translate converts a parsed HTML DOM into a slice of Paper rows.
Index ¶
- Variables
- func Hamilton(weights []float64, total int) []int
- func NewPageBreakRow() core.Row
- func Translate(doc *dom.Document, opts ...Option) ([]core.Row, error)
- func TranslateCtx(ctx context.Context, doc *dom.Document, opts ...Option) ([]core.Row, error)
- type ImageResolver
- type Option
- func WithContentWidth(mm float64) Option
- func WithGridSize(n int) Option
- func WithImageBaseDir(dir string) Option
- func WithImageResolver(fn ImageResolver) Option
- func WithLimits(l htmllimits.Limits) Option
- func WithStylesheetBaseDir(dir string) Option
- func WithUnsupportedHandler(fn func(thing, value string)) Option
- type StylesheetResolver
Constants ¶
This section is empty.
Variables ¶
var ErrImageResolverRefused = errors.New(
"html: default resolver refuses local file reads; configure html.WithImageBaseDir or translate.WithImageResolver",
)
ErrImageResolverRefused is returned by the default resolver when asked to load a non-data: URI without an explicit html.WithImageBaseDir or the lower-level translate.WithImageResolver.
var ErrStylesheetResolverRefused = errors.New("html: default stylesheet resolver refuses local file reads; configure WithStylesheetBaseDir")
ErrStylesheetResolverRefused is returned by the default resolver when asked to load a non-data: URI without an explicit WithStylesheetBaseDir.
Functions ¶
func Hamilton ¶
Hamilton distributes total integer units across items proportionally to their weights using the largest-remainder method (Hamilton's method). Returns []int{} for empty input; zero-weight inputs get equal split.
func NewPageBreakRow ¶
NewPageBreakRow creates an exported pageBreakRow for use in tests and the translate pipeline.
Types ¶
type ImageResolver ¶
ImageResolver loads image bytes for a given <img src="…"> value. It returns the raw bytes and a hint extension ("png", "jpg", "svg", etc.). When err is non-nil the caller falls back to the <img>'s alt text.
type Option ¶
type Option func(*translator)
Option configures translator behaviour.
func WithContentWidth ¶
WithContentWidth sets the content width in mm, used for gap-to-col approximation.
func WithGridSize ¶
WithGridSize overrides the default 12-column grid size used for flex quantization.
func WithImageBaseDir ¶
WithImageBaseDir scopes the default resolver to a single directory. Local file reads outside this directory are refused (path-traversal safe).
func WithImageResolver ¶
func WithImageResolver(fn ImageResolver) Option
WithImageResolver lets callers plug in a custom <img src=…> loader.
func WithLimits ¶
func WithLimits(l htmllimits.Limits) Option
WithLimits configures resource limits for untrusted HTML translation.
func WithStylesheetBaseDir ¶
WithStylesheetBaseDir scopes the default stylesheet resolver to a single directory. Local-file reads outside this directory are refused.
func WithUnsupportedHandler ¶
WithUnsupportedHandler registers a callback for unsupported tags/props.
type StylesheetResolver ¶
StylesheetResolver loads CSS text for a given <link href="…"> value. Returns the raw bytes (UTF-8 CSS text) and any error.