docpdf

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docpdf renders docrender Markdown to PDF by driving external converters as subprocesses; no PDF renderer is linked into the binary.

Index

Constants

View Source
const (
	PandocEnv     = "OPENSYSML_PANDOC"
	WeasyPrintEnv = "OPENSYSML_WEASYPRINT"
	PrinceEnv     = "OPENSYSML_PRINCE"
	MermaidEnv    = "OPENSYSML_MMDC"
	// MermaidPuppeteerEnv names an optional puppeteer configuration file
	// passed to mmdc, for environments whose browser needs launch flags.
	MermaidPuppeteerEnv = "OPENSYSML_MMDC_PUPPETEER"
)

Environment variables that point each external tool's discovery at a specific executable, ahead of a PATH lookup by its default name.

Variables

This section is empty.

Functions

func Engines

func Engines() []string

Engines names the converters, in the order they are offered. The first is the default.

func Render

func Render(markdown, engine string, opts Options) ([]byte, error)

Render converts docrender Markdown to PDF bytes with the named engine ("" selects the default). Diagrams are pre-rendered to SVG with mermaid-cli.

Types

type Capabilities

type Capabilities struct {
	Input         Input
	Tools         []string
	NativeOptions bool
}

Capabilities is what a converter states about itself: the form it reads, the executables it drives, and whether it applies the deliverable options natively rather than through the prepared HTML.

type Converter

type Converter interface {
	// Name is what -pdf-engine selects the converter by.
	Name() string

	// Capabilities states the converter's input form and tools.
	Capabilities() Capabilities

	// Available returns nil, or a typed error naming the missing tool.
	Available() error

	// Convert lays the prepared document out as PDF bytes.
	Convert(doc *Prepared) ([]byte, error)
}

Converter is one external Markdown/HTML-to-PDF toolchain, run as a subprocess.

func EngineNamed

func EngineNamed(name string) (Converter, error)

EngineNamed returns the converter -pdf-engine named, the default for "", and a typed error for a name no converter answers to.

type Error

type Error struct {
	Kind ErrorKind

	// Engine is the converter that was selected, where one was.
	Engine string

	// Tool is the external executable involved: its configured override or
	// its default name for ErrorToolMissing, its path for ErrorToolFailed.
	Tool string

	// EnvVar is the environment variable that overrides where Tool is found.
	EnvVar string

	// Engines lists the converters an unknown -pdf-engine could have named.
	Engines []string

	// Detail carries what the tool said on stderr, trimmed.
	Detail string
}

Error is a typed PDF-rendering failure.

func (*Error) Error

func (e *Error) Error() string

type ErrorKind

type ErrorKind string

ErrorKind classifies a PDF-rendering failure.

const (
	// ErrorUnknownEngine reports a -pdf-engine name no converter answers to.
	ErrorUnknownEngine ErrorKind = "unknown-engine"
	// ErrorToolMissing reports an external tool the selected converter needs
	// that could not be found.
	ErrorToolMissing ErrorKind = "tool-missing"
	// ErrorToolFailed reports an external tool that ran and failed.
	ErrorToolFailed ErrorKind = "tool-failed"
	// ErrorNoPDF reports a converter that succeeded without producing a PDF.
	ErrorNoPDF ErrorKind = "no-pdf"
	// ErrorUnclosedFence reports a Mermaid fence the Markdown never closes.
	ErrorUnclosedFence ErrorKind = "unclosed-fence"
	// ErrorDanglingCaption reports a caption marker not followed by a
	// fully-emphasized caption line.
	ErrorDanglingCaption ErrorKind = "dangling-caption"
)

type Input

type Input string

Input is the document form a converter reads.

const (
	InputHTML     Input = "html"
	InputMarkdown Input = "markdown"
)

type Options

type Options struct {
	// TitlePage puts the document title on a page of its own.
	TitlePage bool

	// TOC writes a table of contents ahead of the content.
	TOC bool

	// NumberSections numbers the section headings hierarchically.
	NumberSections bool
}

Options are the deliverable-document choices the PDF backend offers. They are presentation options of this backend, never document-model attributes.

type Prepared

type Prepared struct {
	// Dir is the working directory holding every input, diagram SVGs included.
	Dir string

	// MarkdownFile is the Markdown document's name within Dir.
	MarkdownFile string

	// HTMLFile is the HTML document's name within Dir.
	HTMLFile string

	// Options are the deliverable choices, for converters with native flags.
	Options Options
}

Prepared is one document laid out in a working directory for a converter, as both Markdown (diagrams as image references) and standalone HTML.

Jump to

Keyboard shortcuts

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