docxwrite

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package docxwrite renders a cssbox tree (the shared box model produced by the HTML, DOCX, Markdown, and PDF-extraction frontends) to a WordprocessingML (.docx) package. Like the Markdown and HTML writers — and unlike the raster and PDF backends — it is a STRUCTURE writer: it walks the box tree directly, reading the semantic annotations (SemTag/HeadingLvl/Href), display kinds, and computed style, and emits headings, paragraphs, emphasis, hyperlinks, lists, block quotes, and code blocks as native Word constructs. It is deliberately not layout-faithful: floats, positioning, and exact CSS geometry are not represented (they degrade to normal flow), and headers/footers and footnotes are out of scope.

The walk BUILDS a *docx.Document — the public model in pkg/docx — and serializes it with docx.Write, so the repo has exactly one OPC emitter. Every mapping is chosen so this repo's own DOCX reader (pkg/docx + pkg/docx/cssbox) round-trips it: heading level rides on the HeadingN style id, quotes on the Quote style, code blocks on the CodeBlock style, emphasis on direct run properties, hyperlinks on external relationships.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(ctx context.Context, root *cssbox.Box, w io.Writer, opts Options) error

Write renders the cssbox tree rooted at root to w as a complete .docx package. root is expected to be a finalized tree (post box-generation fixups). A nil root writes a valid empty document.

Types

type Options

type Options struct {
	// PageWidthPt, PageHeightPt set the section page size in points; default US
	// Letter (612x792) when zero.
	PageWidthPt, PageHeightPt float64
	// MarginPt is the uniform page margin in points; default 72 (1in, Word's
	// default) when zero. A negative value means no margin (0).
	MarginPt float64
	// Loader resolves image refs (an <img> src) to bytes for embedding as media
	// parts. nil means images degrade to their alt text (logged).
	Loader resource.ResourceLoader
	// Logf receives degradation diagnostics (e.g. a construct the writer cannot
	// represent). nil -> no-op.
	Logf func(string, ...any)
}

Options configures DOCX output.

Jump to

Keyboard shortcuts

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