Skip to content
@deckyard/docs

Doctree and Markdown

The bundled doctree is the tree markdown, rst and myst parse into and the renderers draw from. fromDoctree turns one into a document; toDoctree turns a document back, so a document renders to HTML and PDF.

jennifer
import "@deckyard/docs/" as docs;
use fs;

def d as docs.Document init docs.fromMarkdownWith(fs.readString("README.md"), {"logo.png": fs.readBytes("logo.png")});
docs.save($d, "README.docx");

Mapping

doctreedocument
headingheading paragraph, level 1 to 6
paragraph, lineparagraph
code, html_blockone "code" paragraph, lines as line ends in the text
list / itema ListDef per list; items as list paragraphs, a nested list one level deeper; an item's later paragraphs as body text; task items with a ballot box
table / row / celltable with colspan, rowspan, alignment and headerRows; a table title as a "caption" paragraph before it
quote, admonition, topic"quote" paragraphs, a title first in bold
definition_list"term" and "definition" paragraphs
thematic_break"rule" paragraph
page_breakpage break
footnote / footnote_refa note and its reference
figurethe picture and a "caption" paragraph
strong, emphasis, strikethrough, highlight, subscript, superscript, codespanthe matching RunStyle flags, nested
link, image, line_breaklink target, picture, line break
html_inline, span, abbr, citetheir text

Pictures need their data: fromDoctreeWith and fromMarkdownWith take it by the URL the tree writes. An image whose URL the map lacks is an error, not a silent omission.

Back to a doctree

toDoctree maps the other way; toHtml and toPdf render through it.

documentdoctree
list paragraphsnested list / item by listLevel, with start and enumtype
consecutive "quote" paragraphsone quote
consecutive "code" paragraphsone code, lines joined by line ends
"term" / "definition"definition_list
"rule"thematic_break
"title"heading 1 with class title
"subtitle"rubric
"caption"paragraph with class caption
notesfootnote nodes at the end, footnote_ref where they are referred to
picturesimage with the media name as URL; toHtml embeds them as data: URIs, toPdf loads them

Deleted tracked text, comments and underline (which doctree has no kind for) are left out.

jennifer
import "@deckyard/docs/" as docs;
use fs;

def d as docs.Document init docs.open("report.docx");
fs.writeString("report.html", docs.toHtml($d));
fs.writeBytes("report.pdf", docs.toPdf($d));