A document template language whose templates declare their own data contract.

What does not satisfy the contract does not render. Not a mode, not a flag: the engine proves, before it sees the data, that no gap can reach the text.

Linguagem de modelos de documento e seu motor, em Julia. O modelo declara seu contrato; o que não satisfaz o contrato não renderiza.

  • Julia 1.10+ core, three layers and a language server
  • 2,747 tests Linux, macOS and Windows, with pandoc
  • 15 real templates the gate is closed, and the syntax is frozen
  • MIT free to use, fork and extend
Kanon: a woman looking upward inside a golden halo, a four-pointed star over her face.

I — The engine

Write the template. The engine answers.

Three scenes, in a loop: a document that renders, a contract that is not satisfied, and a field that does not exist. The messages are not mock-ups — they are what the engine prints.

preamble.kanon
terminal
out.md
scene 1 / 3 — it renders

Transcript of the animation

Scene 1. The template declares seller of type person, required; price of type money, required; notes of type text, optional. The text block preamble reads: {seller.name} sells for {price}, followed by a bracketed group “, noting that {notes}”. The command kanon render preamble.kanon data.json -o out.md produces “Maria Souza sells for R$ 250.000,00.” The optional value is absent, so the whole group is elided, comma and all.

Scene 2. With price removed from the data, kanon check reports one problem: contract, required field missing, code K3001, line 5 column 3: `price` is required by the template and was not supplied. No document is produced — not a document with a gap.

Scene 3. With seller.name mistyped as seller.nmae: reference, field does not exist on type, code K2003, line 10 column 1: `person` has no field `nmae`. Did you mean `name`? Fields of `person`: name, spouse.


II — What is its own

The gap theorem

The one item of the survey with no precedent found: not “the field exists”, but “the gap cannot appear” — and proved before any data is seen.

If check(tmpl) passes and check(tmpl, data) passes, then render(tmpl, data) contains no text originating from an absent value, and no text whose reading depends on one.

No lenient mode

No mode, option or flag ever renders with an unsatisfied contract. It does not exist, not even as a convenience — a document missing a clause is worse than no document.

No null of its own

No type has a null of its own: there is no empty money and no invalid date. Blank text is an error in a required field and null in an optional one.


III — The file

Three planes, one file

The contract, the prose and the rules live in the file the writer edits — not in a component file owned by another tool and another person.

lease.kanon
data — the contract

Fields, types, cardinality and requiredness. ! is required, [1..] is one or more, a default fills what is missing. This is what kanon contract emits as JSON Schema.

text — the prose

Blocks, numbering and cross-references. [ ] marks a group that disappears whole when a value inside it is absent, punctuation and all.

rules — remove or repeat

The anti-XSLT invariant: rules never insert, never substitute, never reorder. The order of the blocks in the output is the order of the text plane, so reading the file is a reliable upper bound on the document.


IV — Prior art

Where the contract lives

Plenty of systems check something. The question is where the contract is written, when it is verified, and whether it can prove that a gap never reaches the text.

SystemWhere the contract livesChecked when Prevents the gap?Readable by a non-programmer
Liquid / Mustachenowhere— noyes
Jinja2 StrictUndefinedimplicitrender, in production the field only, not the gapyes
Askamaa Rust structcompile time the field onlyno
HotDocsa component fileassembly the field onlypartly
docassembleYAML + Pythoninterview turns it into a questionno
CUE / Dhallthe file itselfevaluation yes — but produces no proseno
Kanonthe template itself before rendering, without datayes that is the requirement

V — Getting started

Two doors, the same engine

The library from Julia, and the command line the writer actually uses.


VI — Extension

Layers by multiple dispatch

The core knows no language and no domain. A layer adds methods — there is no registry of formatters kept by hand, and a test fails if anything Portuguese or legal appears inside the core.

Language · pt

Extenso.jl

Inflection by mark, numbers, ordinals, money and dates spelled out, list joining, separators, keywords in Portuguese. Publishable on its own.

Domain

KanonLegal.jl

Types pessoa, imovel, parte; the § style that numbers CLÁUSULA PRIMEIRA.

Domain

KanonScience.jl

The measure type, with uncertainty carrying the digits the measurement supports, and the @ style that numbers theorems.

dispatch

VII — Output

The engine guarantees the content

Page composition belongs to something that knows how to do it: --to markdown | pandoc -o deed.docx.

textmarkdowntypst

An interpolated value never alters the structure

The author's prose passes through untouched — **important** stays bold — and the data is escaped. A name containing # cannot open a heading.

The number the engine computed is the number that appears

A label like 1. at the start of a line is a list marker in Markdown, so it is escaped; the cross-reference in the prose keeps pointing at the right clause.