manifold

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 3 Imported by: ? 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.

README

Manifold

CI and Release

Pure-Go rich document processing for embedded applications and the command line.

Convert DOCX → structured format → DOCX/PDF, and recover structured content from PDF. The shared format is a versioned ProseMirror JSON profile, with typed Go trees for programmatic manipulation. Runtime conversion needs no CGO, external executables, services or license servers.

Install

Go 1.25 or newer:

go get github.com/artpar/manifold
go install github.com/artpar/manifold/cmd/manifold@latest

CLI

manifold extract -format sf -o document.sf input.docx
manifold convert -allow-lossy -o document.docx document.sf
manifold convert -allow-lossy -o document.pdf document.sf
manifold extract -format sf -o recovered.sf document.pdf

Flags precede the input filename. Review import diagnostics before acknowledging losses with -allow-lossy. Unsupported output still rejects. .sf.gz compresses the same structured format. The CLI commits an output file only after success.

Go API

import "github.com/artpar/manifold"

doc, err := manifold.Read(ctx, source, manifold.DOCX, manifold.ReadOptions{})
if err != nil {
    return err
}
return manifold.Write(ctx, destination, doc, manifold.SF, manifold.WriteOptions{})

The public package exposes document types, conversion functions, options and errors. Callers own readers/writers, persistence and authorization. See sections, rich tables and notes for complete examples.

Conversion model

SF is the canonical structured representation shared by the converters:

DOCX ↔ SF ↔ PDF
       ↕
     VDOCS

VDOCS is optional native snapshot interchange, not another canonical model or a second DOCX/PDF pipeline. Word support is DOCX; legacy binary DOC is not provided. PDF import reconstructs recoverable structure and positions with diagnostics; source-identical layout is not promised.

Support and layout

Paragraphs/headings, formatted runs, links, lists, merged/nested tables, images, metadata, page settings, headers/footers and rich notes share the same model. PDF extraction distinguishes explicit structure from geometric inference and retains physical pages, positions, navigation and assets. Missing glyphs, unsupported shaping and representation losses have explicit outcomes.

The optional offline VDOCS adapter supports a qualified native editor snapshot profile; no editor service is required. Existing files retain manydoc-prosemirror/1 and embedded metadata identifiers for compatibility. This is not a Word layout engine or full UniDoc API replacement.

manifold.go          public API
cmd/manifold/        CLI and file handling
internal/engine/     conversion model, codecs and layout; adjacent unit tests
internal/bidilevels/ attributed bidi algorithm and conformance data
examples/            runnable public API examples
scripts/qa/          optional independent qualification, grouped by concern
testdata/            pinned synthetic and original reference documents
docs/                current guides, reference contracts, reports and history

Start with documentation, compatibility, verification or testing. Original-source fixtures and third-party notices are documented in THIRD_PARTY.md. The project is MIT licensed.

CI and releases

GitHub Actions tests pushes and pull requests on Linux, macOS and Windows, with race checks on Linux. A new version in VERSION on main automatically creates the tag and release after checks pass. The pipeline builds CGO-disabled binaries for Linux/macOS/Windows on amd64/arm64, packages licenses and publishes checksums. See CI/CD. No workstation build/upload step is needed for releases.

Documentation

Overview

Package manifold reads, writes and converts rich documents in pure Go.

Index

Constants

View Source
const AnchorPoint = engine.AnchorPoint
View Source
const DOCX = engine.DOCX
View Source
const Endnote = engine.Endnote
View Source
const Footnote = engine.Footnote
View Source
const Heading = engine.Heading
View Source
const JSON = engine.JSON
View Source
const ListBlock = engine.ListBlock
View Source
const PDF = engine.PDF
View Source
const PageBreak = engine.PageBreak
View Source
const Paragraph = engine.Paragraph
View Source
const Picture = engine.Picture
View Source
const SF = engine.SF
View Source
const SFGzip = engine.SFGzip
View Source
const SectionBlock = engine.SectionBlock
View Source
const SectionContinuous = engine.SectionContinuous
View Source
const SectionEvenPage = engine.SectionEvenPage
View Source
const SectionNextPage = engine.SectionNextPage
View Source
const SectionOddPage = engine.SectionOddPage
View Source
const StructuredSchema = engine.StructuredSchema
View Source
const Table = engine.Table
View Source
const Text = engine.Text
View Source
const VDOCS = engine.VDOCS
View Source
const VDOCSMIME = engine.VDOCSMIME

Variables

View Source
var ErrLossy = engine.ErrLossy
View Source
var ErrUnsupported = engine.ErrUnsupported

Functions

func Write

func Write(ctx context.Context, w io.Writer, d *Document, format Format, opts WriteOptions) error

Write encodes the document, applying the selected loss and font policies.

func WriteStructured

func WriteStructured(ctx context.Context, w io.Writer, s *StructuredDocument) error

WriteStructured validates and writes the ProseMirror profile.

func WriteVDOCS

func WriteVDOCS(ctx context.Context, w io.Writer, d *Document) error

WriteVDOCS encodes the supported VDOCS native document envelope.

Types

type Block

type Block = engine.Block

type Cell

type Cell = engine.Cell

type Diagnostic

type Diagnostic = engine.Diagnostic

type Document

type Document = engine.Document

Document is manifold's interchange model. Diagnostics describe input features whose structure cannot be represented. Converters reject lossy output unless the caller explicitly acknowledges those diagnostics.

func FromStructured

func FromStructured(s *StructuredDocument) (*Document, error)

FromStructured validates and converts a ProseMirror tree to the document model.

func Read

func Read(ctx context.Context, r io.Reader, format Format, opts ReadOptions) (*Document, error)

Read decodes a supported format into the shared document model.

func ReadDOCX

func ReadDOCX(ctx context.Context, src io.Reader) (*Document, error)

ReadDOCX extracts supported DOCX content and representation-loss diagnostics.

func ReadPDF

func ReadPDF(ctx context.Context, src io.Reader, opts ReadOptions) (doc *Document, err error)

ReadPDF recovers PDF content, physical source facts and qualified structure.

func ReadVDOCS

func ReadVDOCS(ctx context.Context, r io.Reader) (*Document, error)

ReadVDOCS decodes the supported VDOCS native document envelope.

type FontFace

type FontFace = engine.FontFace

FontFace supplies one embeddable TTF program under a lookup family name. Bold/Italic select its request slot; the supplied outlines determine appearance. The renderer does not synthesize missing variants.

type Format

type Format = engine.Format

func FormatFromName

func FormatFromName(name string) (Format, error)

FormatFromName identifies a supported format from a filename.

type Image

type Image = engine.Image

type Kind

type Kind = engine.Kind

type Layout

type Layout = engine.Layout

Layout dimensions are points, 72 per inch. Zero Width/Height/Margin use A4 and the legacy 54pt fallback. Margins and distance pointers retain explicit zeros.

type ListItem

type ListItem = engine.ListItem

ListItem owns its ordered blocks, including continuation paragraphs and nested lists.

type ListMarker

type ListMarker = engine.ListMarker

ListMarker retains literal visible label content and its independent source owner. It does not define an automatic numbering or restart rule.

type ListNumbering

type ListNumbering = engine.ListNumbering

ListNumbering describes an ordered-list label using OOXML's %1..%9 placeholders. Level is zero-based. Formats contains one format per level; Ancestors contains fallback values for levels before Level. Enclosing lists override matching ancestor levels when serialized, so nested edits renumber. Legal renders every referenced level in decimal, retaining its original format.

type Matrix

type Matrix = engine.Matrix

Matrix is [a b c d e f]: x'=a*x+c*y+e, y'=b*x+d*y+f.

type Metadata

type Metadata = engine.Metadata

type Note

type Note = engine.Note

type NoteReference

type NoteReference = engine.NoteReference

NoteReference identifies a note independently of its displayed automatic number. IDs are scoped by Kind and may be application identifiers rather than integers.

type PDFArtifact

type PDFArtifact = engine.PDFArtifact

PDFArtifact records an explicit marked-content artifact, independently of any inferred reusable header/footer template. BBox uses default user-space units (not the current content CTM); Bounds uses Matrix to map it into displayed physical points. Content refers back here through SourceInfo.Artifacts, including nested marked-content and images.

type PDFDestination

type PDFDestination = engine.PDFDestination

type PDFNavigation

type PDFNavigation = engine.PDFNavigation

PDFNavigation retains explicit PDF annotation/view evidence independently of inferred editable-flow anchors. Coordinates in Point/Region use displayed pt; Parameters retain original PDF user units and nullable viewer settings.

type PDFNavigationLink = engine.PDFNavigationLink

type PDFPage

type PDFPage = engine.PDFPage

PDFPage records physical page boundaries even when a logical tagged paragraph spans pages. Boxes retain PDF user units; Width/Height and source quads use pt.

type PageMargins

type PageMargins = engine.PageMargins

PageMargins overrides all four edges of Layout.Margin. Zero is an explicit zero margin. Top/Bottom may be negative for OOXML fixed body offsets that permit running-content overlap; Left/Right are nonnegative.

type Point

type Point = engine.Point

Point is in physical points in displayed page coordinates: top-left origin, x right and y down. PDFPage.Transform maps original PDF user coordinates here.

type Quad

type Quad = engine.Quad

type ReadOptions

type ReadOptions = engine.ReadOptions

type Row

type Row = engine.Row

type Run

type Run = engine.Run

type RunningStories

type RunningStories = engine.RunningStories

RunningStories distinguishes an inherited nil story from an explicit empty one. Default serves odd pages (and all ordinary pages without EvenAndOddHeaders).

type RunningStory

type RunningStory = engine.RunningStory

RunningStory is an independently inherited header or footer variant. A non-nil story with no blocks explicitly suppresses that variant.

type Section

type Section = engine.Section

Section owns body content. Layout nil inherits the previous effective layout (the document layout for the first section). Stories inherit independently. Native PDF keeps the stories of the section that opened a physical page. A continuous section counts a shared page as local page one, even when its body is empty. Later pages select its default/even stories using that count.

type SectionStart

type SectionStart = engine.SectionStart

SectionStart controls the section start relative to the preceding section. An empty value means nextPage; the first section starts the document.

type SourceElementReference

type SourceElementReference = engine.SourceElementReference

SourceElementReference retains an explicit logical cell that was an empty continuation of a geometrically recovered merged cell.

type SourceInfo

type SourceInfo = engine.SourceInfo

SourceInfo records provenance, not an alternative copy of content. Quads use advance/font metrics, not glyph ink outlines. Precision discloses estimates. Confidence is a heuristic ranking, not a calibrated probability.

type SourceRegion

type SourceRegion = engine.SourceRegion

type SourceStructureReference

type SourceStructureReference = engine.SourceStructureReference

SourceStructureReference identifies the explicit owner and targets of a PDF structure Ref entry. Aggregate source bounds retain contributing edges too.

type StructuredAttributes

type StructuredAttributes = engine.StructuredAttributes

type StructuredDocument

type StructuredDocument = engine.StructuredDocument

StructuredDocument is a ProseMirror document using the versioned schema in docs/reference/STRUCTURED_FORMAT.md. It needs no JavaScript or ProseMirror runtime.

func ReadStructured

func ReadStructured(ctx context.Context, r io.Reader) (*StructuredDocument, error)

ReadStructured reads and validates the ProseMirror profile.

func ToStructured

func ToStructured(d *Document) (*StructuredDocument, error)

ToStructured converts the document model to its ProseMirror representation.

type StructuredMark

type StructuredMark = engine.StructuredMark

type StructuredNode

type StructuredNode = engine.StructuredNode

Attrs contains the attributes defined for this node type, encoded as an object. Unknown nodes, marks and attributes are rejected, never silently flattened.

type StructuredNote

type StructuredNote = engine.StructuredNote

type TableSpanSource

type TableSpanSource = engine.TableSpanSource

TableSpanSource separates explicit logical membership from recovered spans. ColSpan and RowSpan are "explicit" or "inferred". Bounds records the painted cell boundary; SourceInfo.Quad continues to record its content bounds.

type TableWidthSource

type TableWidthSource = engine.TableWidthSource

TableWidthSource records measured painted-grid widths independently from explicit PDF logical table membership. Confidence is not a probability.

type WriteOptions

type WriteOptions = engine.WriteOptions

Directories

Path Synopsis
cmd
manifold command
examples
bidi command
Bidi layout uses paragraph context, directional shaping and logical text.
Bidi layout uses paragraph context, directional shaping and logical text.
continuous command
Four conversion paths with shared-page story changes and section-local parity.
Four conversion paths with shared-page story changes and section-local parity.
continuous-admission command
Four conversion paths for individually valid continuous stories needing new pages.
Four conversion paths for individually valid continuous stories needing new pages.
continuous-geometry command
Four conversion paths with changing continuous body frames and paper canvases.
Four conversion paths with changing continuous body frames and paper canvases.
destinations command
Named navigation points through SF, DOCX, native PDF and PDF view recovery.
Named navigation points through SF, DOCX, native PDF and PDF view recovery.
font-subset command
Exercise all four SF conversion paths with an explicitly supplied TTF.
Exercise all four SF conversion paths with an explicitly supplied TTF.
glyphs command
image-fit command
Run with: GOWORK=off go run ./examples/image-fit -out output/image-fit
Run with: GOWORK=off go run ./examples/image-fit -out output/image-fit
language command
Language bindings and paragraph/run direction persist through SF and DOCX.
Language bindings and paragraph/run direction persist through SF and DOCX.
lists command
Run with: GOWORK=off go run ./examples/lists -out output/lists
Run with: GOWORK=off go run ./examples/lists -out output/lists
merged-tables command
Run with: GOWORK=off go run ./examples/merged-tables -out output/merged-tables
Run with: GOWORK=off go run ./examples/merged-tables -out output/merged-tables
notes command
Run with: GOWORK=off go run ./examples/notes -out output/notes
Run with: GOWORK=off go run ./examples/notes -out output/notes
numbering command
Numbering formats, nested edits, external contexts and rich stories via SF.
Numbering formats, nested edits, external contexts and rich stories via SF.
page-breaks command
Run with: GOWORK=off go run ./examples/page-breaks -out output/page-breaks
Run with: GOWORK=off go run ./examples/page-breaks -out output/page-breaks
page-layout command
Four conversion paths with explicit asymmetric/zero margins and running offsets.
Four conversion paths with explicit asymmetric/zero margins and running offsets.
paint-context command
Compatible typography keeps context across color, decorations and links.
Compatible typography keeps context across color, decorations and links.
paragraph-breaks command
Run with: GOWORK=off go run ./examples/paragraph-breaks -out output/paragraph-breaks
Run with: GOWORK=off go run ./examples/paragraph-breaks -out output/paragraph-breaks
recursive-tables command
Run with: GOWORK=off go run ./examples/recursive-tables -out output/recursive-tables
Run with: GOWORK=off go run ./examples/recursive-tables -out output/recursive-tables
repeated-headers command
Run with: GOWORK=off go run ./examples/repeated-headers -out output/repeated-headers
Run with: GOWORK=off go run ./examples/repeated-headers -out output/repeated-headers
report command
Run with: go run ./examples/report -out output
Run with: go run ./examples/report -out output
rich-cells command
Run with: GOWORK=off go run ./examples/rich-cells -out output/rich-cells
Run with: GOWORK=off go run ./examples/rich-cells -out output/rich-cells
running-content command
Rich running stories are measured once and repeated without body overlap.
Rich running stories are measured once and repeated without body overlap.
running-images command
Budgeted DOCX running rasters, including serial, nested and body figures.
Budgeted DOCX running rasters, including serial, nested and body figures.
section-controls command
Four conversion paths for page controls, empty sections and note ownership.
Four conversion paths for page controls, empty sections and note ownership.
sections command
Four paths with section-specific geometry, inheritance and running variants.
Four paths with section-specific geometry, inheritance and running variants.
shaping command
Default text shaping needs no language tag or external runtime font service.
Default text shaping needs no language tag or external runtime font service.
signed-overlap command
Four conversion paths for minimum and signed fixed running/body margins.
Four conversion paths for minimum and signed fixed running/body margins.
table-continuation command
Run with: GOWORK=off go run ./examples/table-continuation -out output/table-continuation
Run with: GOWORK=off go run ./examples/table-continuation -out output/table-continuation
table-widths command
Preferred grid widths, merged cells, nested layout and continued headers.
Preferred grid widths, merged cells, nested layout and continued headers.
tagged-spans command
Extract an original tagged PDF and emit a small provenance audit and SF sample.
Extract an original tagged PDF and emit a small provenance audit and SF sample.
text-style command
Run with: GOWORK=off go run ./examples/text-style -out output/text-style
Run with: GOWORK=off go run ./examples/text-style -out output/text-style
typography command
Typography exercises proportional Unicode spacing and line breaking in Go.
Typography exercises proportional Unicode spacing and line breaking in Go.
uri command
Unicode IRI targets retain their URI semantics through the four SF paths.
Unicode IRI targets retain their URI semantics through the four SF paths.
vdocs command
Run from the repository root: GOWORK=off go run ./examples/vdocs -out output/vdocs-example
Run from the repository root: GOWORK=off go run ./examples/vdocs -out output/vdocs-example
internal
bidilevels
Package bidilevels retains paragraph embedding levels for line layout.
Package bidilevels retains paragraph embedding levels for line layout.

Jump to

Keyboard shortcuts

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