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.
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.
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.
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.
Ifcheck(tmpl)passes andcheck(tmpl, data)passes, thenrender(tmpl, data)contains no text originating from an absent value, and no text whose reading depends on one.
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 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.
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.
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.
Blocks, numbering and cross-references. [ ] marks a group that disappears whole when a value inside it is absent, punctuation and all.
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.
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.
| System | Where the contract lives | Checked when | Prevents the gap? | Readable by a non-programmer |
|---|---|---|---|---|
| Liquid / Mustache | nowhere | — | no | yes |
| Jinja2 StrictUndefined | implicit | render, in production | the field only, not the gap | yes |
| Askama | a Rust struct | compile time | the field only | no |
| HotDocs | a component file | assembly | the field only | partly |
| docassemble | YAML + Python | interview | turns it into a question | no |
| CUE / Dhall | the file itself | evaluation | yes — but produces no prose | no |
| Kanon | the template itself | before rendering, without data | yes | that is the requirement |
The library from Julia, and the command line the writer actually uses.
kanon checkValidates the template, and the data against the contract.kanon renderWrites the document — or nothing at all, with the reason.kanon contractEmits the checklist as JSON Schema 2020-12, byte-stable for diffs.kanon previewThe draft: what is missing shows as «marker», and never exports.kanon outlineThe skeleton: blocks, levels, rules, the fields each one uses.kanon askAsks for what is missing, one field at a time, and checks each answer.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.
Inflection by mark, numbers, ordinals, money and dates spelled out, list joining, separators, keywords in Portuguese. Publishable on its own.
Types pessoa, imovel, parte; the §
style that numbers CLÁUSULA PRIMEIRA.
The measure type, with uncertainty carrying the digits the measurement
supports, and the @ style that numbers theorems.
Page composition belongs to something that knows how to do it:
--to markdown | pandoc -o deed.docx.
The author's prose passes through untouched — **important** stays bold — and
the data is escaped. A name containing # cannot open a heading.
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.