Documentation
¶
Overview ¶
Package odf converts between ODT (OpenDocument Text) packages and the neutral github.com/go-richdoc/richdoc document model.
An ODT file is a ZIP container of XML parts. Parse opens the container, reads content.xml (resolving inline formatting against the automatic styles there and the named styles in styles.xml), consults META-INF/manifest.xml for embedded image media types, and maps the office:text body onto richdoc blocks and inlines. Write produces a minimal, valid OpenDocument Text package: the mimetype entry is written first and stored uncompressed, as the OpenDocument packaging specification requires.
The two directions are designed as a faithful round-trip: Parse(Write(d)) is semantically equal to d for the supported model.
Footnotes, bookmarks and cross-references map onto native ODF elements: richdoc.Footnote ↔ text:note, richdoc.Anchor ↔ text:bookmark, and richdoc.CrossRef ↔ text:bookmark-ref (text:reference-ref is also accepted on parse). ODF has no first-class citation element, so a CrossRef of kind richdoc.RefCite is written as a bookmark-ref tagged with the private attribute odfgo:cite="true" that Parse restores to RefCite; an ODF endnote is normalized to a Footnote on the round-trip.
OpenDocument has no dedicated element for several other richdoc nodes (code blocks, block quotes, thematic breaks, inline/display math); those are written using standard ODF container elements tagged with attributes in a private namespace ("https://github.com/go-odf/odf"), which ODF consumers ignore and which let Parse re-recognize the node. Any remaining unrecognized element is preserved verbatim through richdoc.RawInline / richdoc.RawBlock with Format "odf", so nothing in the source is lost.
The package is pure Go and builds with CGO disabled, including for GOOS=js/GOARCH=wasm.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse converts the bytes of an ODT (OpenDocument Text) package into a richdoc.Document.
It opens the ZIP container, resolves inline formatting in content.xml against the automatic styles there and the named styles in styles.xml, reads embedded image bytes (surfaced as data: URIs) using META-INF/manifest.xml for their media types, and reads document metadata from meta.xml. Unrecognized elements are preserved verbatim as richdoc.RawBlock / richdoc.RawInline with Format "odf". A container that is not a ZIP, that lacks content.xml, that holds a corrupt entry, or whose XML is malformed returns an error.
func Write ¶
Write renders a richdoc.Document as the bytes of a minimal, valid OpenDocument Text (.odt) package.
The returned ZIP always begins with a stored (uncompressed) mimetype entry, as the OpenDocument packaging specification requires, followed by META-INF/manifest.xml, content.xml, styles.xml, an optional meta.xml (when the document carries metadata) and any embedded Pictures/. Inline formatting is generated as automatic text styles in content.xml.
Write is the inverse of Parse over the supported model: parsing Write's output reproduces the input tree. An richdoc.Image whose URL is a data: URI is decoded and re-embedded; a malformed data: URI is the only input that makes Write fail.
Types ¶
This section is empty.