The model
A Document is one section: a body of blocks, a page, a header and a footer, and the lists, footnotes, pictures and comments the blocks refer to. Every format reads into it and writes from it, so a conversion is a read and a write.
Blocks
kind | Holds |
|---|---|
"paragraph" | inlines, a role in style, an alignment, and list membership |
"table" | rows of cells, each holding blocks; headerRows |
"pagebreak" | nothing |
A paragraph's style is its role, not a format's style name:
style | DOCX style | ODT style |
|---|---|---|
"" | Normal | Text body |
"heading" (with level 1 to 6) | Heading 1 to 6 | Heading 1 to 6 |
"title", "subtitle" | Title, Subtitle | Title, Subtitle |
"quote" | Quote | Quotations |
"code" | Source Code | Preformatted Text |
"caption" | caption | Caption |
"term", "definition" | Term, Definition | Term, Definition |
"rule" | Horizontal Rule (a bottom border) | the same |
A list item is a paragraph with listId above 0, pointing 1-based into lists, and a listLevel from 0 to 8. A ListDef is bulleted or numbered, with a start and a number format for every level.
Inlines
kind | Means |
|---|---|
"text" | text with style (a RunStyle) and an optional link |
"tab", "break" | a tab, a line break |
"image" | the picture media names, text its alt text |
"note" | a footnote reference, note indexing notes |
"comment" | where comment note is anchored (read only) |
change is "insert" or "delete" on text a reader found in a tracked change; plainText and the doctree bridge leave deleted text out.
Building
Struct literals of this deck must name every field, so build with the constructors and change fields afterwards:
import "@deckyard/docs/" as docs;
def d as docs.Document init docs.newDocument();
$d.meta.title = "Report";
$d.blocks[] = docs.heading(1, [docs.text("Report")]);
def s as docs.RunStyle init docs.plain();
$s.color = "C00000";
$d.blocks[] = docs.paragraph([docs.text("Status: "), docs.styled("late", $s)]);
$d = docs.addList($d, docs.numbering("decimal", 1));
def steps as int init len($d.lists);
$d.blocks[] = docs.listItem($steps, 0, [docs.text("Write")]);
$d.blocks[] = docs.listItem($steps, 0, [docs.text("Review")]);
def n as int init len($d.notes);
$d = docs.addNote($d, [docs.paragraph([docs.text("Measured on one host.")])]);
$d.blocks[] = docs.paragraph([docs.text("Fast"), docs.noteRef($n)]);
$d.blocks[] = docs.textTable([["Name", "Age"], ["Ada", "36"]], 1);
docs.save($d, "report.docx");A table cell covered by a span from the left or from above is left out of its row, as in HTML; the writers put the covered cells back where a format needs them.
Pages
Page is in twips (1/1440 inch): a4() (the default) and letter() give the two common sizes. Width above height is landscape.