docx

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 21 Imported by: 1 module, 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 docx writes Markdown as a Word document (.docx, Office Open XML) in pure Go, for Export as Word, the export_docx tool and /export (spec_006_filetools FS-75): GitHub-flavoured Markdown parsed by goldmark, written as WordprocessingML with Word's own heading, list, quote, code and table styles, so the navigation pane, a table of contents and restyling work as in any Word document. Links stay links (to a heading too), local pictures are embedded (SVG too, and a lone HTML <img>), maths becomes Word equations, other raw HTML is skipped, and Mermaid diagrams are kept as their source.

Index

Constants

View Source
const (
	A4     = "A4"
	Letter = "Letter"
)

Page sizes.

Variables

View Source
var ErrNotDocx = errors.New("not a Word document")

ErrNotDocx means the bytes aren't a Word document (a zip with word/document.xml).

View Source
var ErrNotText = errors.New("not a text file")

ErrNotText is returned for input that isn't text.

View Source
var ErrTooLarge = errors.New("the document is too large to preview")

ErrTooLarge means the document's text (word/document.xml) is over maxDocumentXML: too large to preview, though it may well be a Word document.

Functions

func Render

func Render(src []byte, o Options) ([]byte, error)

Render writes Markdown as a .docx file's bytes.

func ToMarkdown added in v0.7.1

func ToMarkdown(data []byte) (string, error)

ToMarkdown reads a Word document's text as Markdown, for a preview: paragraphs, headings (Heading1–6, Title), bold and italic runs, bulleted and numbered list items, tables (their cells' text), hyperlinks' text and line breaks. Images, comments, headers and footers are left out.

Types

type Options

type Options struct {
	// PageSize is A4 or Letter (default A4).
	PageSize string
	// Title is the document's title in its properties; default the first
	// heading.
	Title string
	// ReadImage returns the bytes of an image the Markdown refers to, by
	// its destination as written (relative to the Markdown file). nil
	// writes images as their alt text, as it does for any it can't read.
	ReadImage func(dest string) ([]byte, error)
	// Time is the document's creation date (default now).
	Time time.Time
	// Diagram returns a picture of a fenced block's diagram (a “`mermaid
	// block, by its text), and its width in pixels; ok false keeps the
	// block as its code. nil: every diagram stays code.
	Diagram func(lang, source string) (png []byte, width int, ok bool)
}

Options shape a document.

Jump to

Keyboard shortcuts

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