diaryx.org / projects /

twig

Zig MIT / Apache-2.0

A round-trippable document AST for Markdown, Djot, and HTML.

Where fig parses configuration files, twig parses documents. It's comparable to Pandoc, but with different goals: not conversion for its own sake, but exposing the abstract syntax tree so precise operations can be performed on it — then writing the document back, faithfully.

  • Round-trippable by intent. First-class support is for formats you can edit and re-serialize without loss — not presentation formats like PDF.
  • Markdown. Fully CommonMark 0.31.2 conformant: 652/652 spec examples passing.
  • Djot. 100% conformant with the djot.js corpus — every case that defines an HTML expectation passes.
  • HTML. A generic-markup parser and serializer with forgiving, document-oriented tree construction.
  • An editor surface. Offset-addressed edits, ancestor queries, inline toggles — the operations a text editor needs, defined on the tree.

Where it fits

twig is the document model everything at Diaryx is written against — every entry in a vault is a twig document, and leaf is a rich-text editor over its tree. Standalone, it's a library (crates.io as twig-doc) for anyone who needs to treat markup as data.