markdown

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessFile

func ProcessFile(filename string, opts Options) error

ProcessFile reads a Markdown file and produces a PDF. ProcessFile reads a Markdown file and produces a PDF. The Lua state is owned by this function: a fresh state is created for each pass via opts.SetupLua so that {lua} blocks and the companion script always see a clean environment. Auto-rerun for aux convergence is driven by opts.MaxPasses; oscillation is detected by hashing the written aux content.

func ProcessHTMLFile

func ProcessHTMLFile(filename string, opts Options) error

ProcessHTMLFile reads an HTML file and produces a PDF, driving the same multi-pass aux convergence loop as ProcessFile. Unlike Markdown mode no default CSS is applied — styling comes from <link>, <style>, inline styles, or the --css flag.

func ProcessHTMLString added in v0.0.11

func ProcessHTMLString(l *lua.State, htmlStr, baseDir, outputFilename string, opts Options) error

ProcessHTMLString takes an HTML payload (already in memory), the directory to resolve relative CSS @import / <link> paths against, and an output PDF filename, and runs the same pipeline as ProcessHTMLFile but using the caller-supplied Lua state. Single- pass — embedders that need aux convergence drive the loop themselves (typically: htmlbag Lua bridge from a user script).

Types

type Frontmatter

type Frontmatter struct {
	Title     string         `yaml:"title"`
	Author    string         `yaml:"author"`
	CSS       string         `yaml:"css"`
	Papersize string         `yaml:"papersize"`
	Format    string         `yaml:"format"`
	Lang      string         `yaml:"lang"`
	Extra     map[string]any `yaml:"-"` // all key-value pairs (including the known ones)
}

Frontmatter holds metadata extracted from the YAML front matter block.

type Options

type Options struct {
	Template      bool   // apply Go template expansion before processing
	CSSFile       string // additional CSS file to load
	DebugMarkdown bool   // print expanded Markdown to stdout instead of generating PDF
	DebugHTML     bool   // print generated HTML to stdout instead of generating PDF
	// Format selects a PDF conformance level. "PDF/UA" enables the
	// accessibility tagging pipeline (StructTreeRoot, MarkInfo, role-mapped
	// element tree, XMP pdfuaid:part 1). Empty means a plain PDF.
	Format string
	// Lang is the BCP47 language tag written to the PDF catalog (/Lang) and
	// used as the document-wide hyphenation default. Required for PDF/UA.
	Lang string
	// Title becomes the document /Title (catalog + XMP dc:title). PDF/UA
	// also auto-enables /DisplayDocTitle so PDF readers show the title in
	// the window chrome instead of the filename.
	Title string
	// OutputPath is the resolved PDF output path. If empty, falls back
	// to <input>.pdf alongside the input file.
	OutputPath string
	// MaxPasses caps the auto-rerun loop used to converge the aux file
	// (forward references like total page count). Values <1 are treated
	// as 1 (single pass, no rerun).
	MaxPasses int
	// SetupLua is called once per pass on a fresh lua.State to register
	// modules. May be nil for callers that have already initialised the
	// state (e.g. ProcessHTMLString from the htmlbag bridge — that path
	// reuses the caller's state and ignores SetupLua entirely).
	SetupLua func(l *lua.State)
	// ScriptArgs becomes arg[1..n] in the Lua state. arg[0] is the
	// input filename, arg[-1] is the interpreter (os.Args[0]).
	ScriptArgs []string
	// Result, if non-nil, is populated with end-of-pass statistics.
	// The final pass's data wins. Nil disables collection.
	Result *Result
	// SourceDateEpoch, when non-zero, overrides the PDF CreationDate.
	// Combined with baseline-pdf's already-deterministic /ID (MD5 of
	// xref content) this yields byte-stable PDFs across runs with the
	// same input — the SOURCE_DATE_EPOCH reproducible-builds protocol.
	SourceDateEpoch time.Time
}

Options controls the Markdown processing pipeline.

type Result added in v0.0.15

type Result struct {
	Pages    int                    `json:"pages"`
	Passes   int                    `json:"passes"`
	Headings []htmlbag.HeadingEntry `json:"headings"`
}

Result holds post-run statistics from ProcessFile / ProcessHTMLFile. Callers wanting a manifest pre-allocate one and pass it via Options.Result; the markdown package populates it at the end of each pass (the final pass overwrites earlier values).

Jump to

Keyboard shortcuts

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