ddn.odf.text

Packaged .odt text document model and APIs.

This module provides the text document facade and typed text body model for reading, writing, and creating OpenDocument Text files.

Text constructs

Fully typed:

  • Paragraphs (text:p), headings (text:h), text spans (text:span)
  • Line breaks (text:line-break), tabs (text:tab)
  • Hyperlinks (text:a), bookmarks (text:bookmark, text:bookmark-start/end)
  • Ordered/unordered lists (text:list, text:list-item)
  • Simple tables (table:table, table:row, table:cell)
  • Images in frames (draw:frame > draw:image)
  • Footnotes/endnotes (text:note)
  • Sections (text:section)
  • Common fields (text:date, text:time, text:page-number, etc.)
  • Soft page breaks (text:soft-page-break)

Preservation-first (raw XML retained):

  • Tracked changes, form controls, shapes, annotations
  • Extension elements from third-party office suites
  • Complex draw:frame content beyond simple images

Types 3

Identifies the kind of a text node in the document body.

Used to dispatch on node type without dynamic_cast or class hierarchies.

PARAGRAPH
HEADING
SPAN
HYPERLINK
BOOKMARK
BOOKMARK_START
BOOKMARK_END
LINE_BREAK
TAB
LIST
LIST_ITEM
TABLE
TABLE_ROW
TABLE_CELL
FRAME
IMAGE
SECTION
NOTE
FIELD
SOFT_PAGE_BREAK
UNKNOWN
structTextNode

Discriminated union representing a single inline or block-level text content element.

Each node carries a kind tag and relevant fields depending on the kind. Child nodes are stored in the children array for container nodes (paragraphs, headings, spans, hyperlinks, list items, table cells, sections, notes).

Fields
string styleName
string text
TextNode[] children
XmlElement rawElement
int outlineLevel
string className
string href
string targetFrameName
string bookmarkName
string noteClass
string noteId
string fieldName
string formula
string numberColumnsRepeated
string numberRowsRepeated
string tableName
string imagePath
string anchorType
string frameWidth
string frameHeight
string frameName
string sectionName
string sectionCondition
Methods
bool hasChildren() @safe pure nothrow constReturns `true` if this node has children.
bool isContainer() @safe pure nothrow constReturns `true` if this is a container node (paragraph, heading, span, hyperlink, list item, table cell, section, note).
string plainText() @safe pure nothrow constExtracts the plain text content from this node and its children.

Represents the office:text body of an ODT document.

Contains the top-level block-level nodes (paragraphs, headings, lists, tables, sections, frames, etc.) and provides access to plain text extraction.

Fields
TextNode[] nodes
XmlElement[] unknownElements
OdfTextTrackedChanges trackedChanges
Methods
size_t length() @safe pure nothrow constReturns the number of top-level nodes in the body.
bool isEmpty() @safe pure nothrow constReturns `true` if the body has no nodes.
string plainText() @safe pure nothrow constExtracts the plain text content from all top-level nodes.
TextNode[] paragraphs() @trusted pure constReturns all paragraphs and headings in document order.

Functions 26

private fnvoid collectParagraphs(const TextNode[] nodes, ref TextNode[] result) @trusted pure nothrow
fnOdfTextBody parseTextBody(XmlElement textElement)Parses an `office:text` XML element into an `OdfTextBody`.
fnOdfTextBody emptyTextBody() @safe pure nothrow @nogcCreates an empty `OdfTextBody`.
fnstring serializeTextBody(const ref OdfTextBody body)Serialises an `OdfTextBody` to an `office:text` XML element string.
private fnvoid serializeNode(XmlElement parent, ref const TextNode node)
private fnvoid serializeChildren(XmlElement parent, ref const TextNode[] children)
private fnauto parseOdfXmlForTest(string xml)
fnTextNode paragraph(string text, string styleName = "") @safe pure nothrowCreates a paragraph node with the given style and text content.
fnTextNode heading(string text, int level, string styleName = "") @safe pure nothrowCreates a heading node with the given outline level and text.
fnTextNode hyperlink(string text, string href, string styleName = "") @safe pure nothrowCreates a hyperlink node.
fnTextNode span(string text, string styleName) @safe pure nothrowCreates a span node.
fnTextNode list(TextNode[] items...) @safe pure nothrowCreates a list node containing the given items.
fnTextNode table(TextNode[] rows...) @safe pure nothrowCreates a simple table node.
fnTextNode tableRow(TextNode[] cells...) @safe pure nothrowCreates a table row node.
fnTextNode tableCell(string text, string styleName = "") @safe pure nothrowCreates a table cell node.
fnTextNode imageFrame(string imagePath, string width = "", string height = "", string anchorType = "paragraph") @safe pure nothrowCreates an image frame node.