
November 30, 2026
Title Blocks as Finite Automata: How Our CMS Governs Page Components
Or how I learned to stop worrying and apply automata theory to content management.
Look at the top of this page. A date, a title, and a one-sentence lead beneath the title. Every post on this site opens with those three elements, in that order.
The component is called a Title Block, and it was designed around the concept of a DFA (Deterministic Finite Automaton) from computer science theory.
NOTICE: From here on out this post is AI generated content describing how the system works.
In Accent, a component is four things: a contract, a rule, a template, and a matcher that reads the rule. You write the first three for each component. The fourth is written once and reads them all.
The contract
The contract is a JSON file. This is the whole of this site’s title block:
{
"id": "title-block",
"title": "Title block",
"kind": "component",
"grammar": "mk-title-block",
"children": {
"content": "eyebrow heading lead"
},
"output": {
"format": "fragment",
"renderer": "title-block.ejs",
"visibility": "public"
}
}Nothing in it says what the block looks like. There is no tag in it, no font and no spacing. id and title name it. output says it prints a piece of HTML, not a page, and names the template that prints it. grammar is the design’s class name for the block. It is not the rule.
The rule is the line under children. It says what the block holds: an eyebrow, then a heading, then a lead. The block has no fields of its own. Its content is its children.
The parts
Each name in the rule is a component too, with a contract of its own. This is the heading:
{
"id": "heading",
"title": "Heading",
"kind": "component",
"grammar": "page-title",
"fields": [
{ "id": "text", "label": "Text", "kind": "scalar", "data_type": "string", "editor": "text_input" }
],
"children": { "content": "text" },
"output": { "format": "fragment", "renderer": "heading.ejs", "visibility": "public" }
}Two things are different. It has one field, its text. And where the block had a rule, the heading has the reserved word text. That word means the part holds no children. It holds words, and the words are typed in place on the page. A part like that is an element.
There is a second reserved word, atom. An atom holds no children and no words. Its template prints the whole thing. The eyebrow on this page is an atom: it prints the post’s date, and nobody types it.
So a part is one of three kinds. A text element is typed. An atom is printed whole. A container holds parts, and has a rule.
The rule
eyebrow heading lead is the plainest rule there is: three parts, in order, all required. The design system these sites share has a looser title block, and its rule uses the whole notation:
(eyebrow | badge)? (heading subheading? lead? | lead)Read it aloud. An eyebrow or a badge, or neither. Then a heading, with a subheading and a lead if you want them, or else a lead alone. Never an eyebrow and a badge together. Never a subheading without a heading. Never nothing.
That is a regular expression. Its alphabet is component names instead of characters. A space means then. | means or. ? means optional, * any number, + one or more. Parentheses group.
A list of allowed children cannot say this. A list says what may go in. A rule says what may go where, and how many.
The level above works the same way. The node that holds a post’s title block has a rule too. Shortened, it is:
title-block (content | image)*A title block first, then writing and pictures in any order. content is the last reserved word: it stands for ordinary writing, the paragraphs and headings and lists you are reading now. A page is rules inside rules, and the title block is one level of it.
The matcher
A rule is a string until something can answer questions with it. The standard way to make a regular expression answer questions is to compile it to a state machine. Here is that, whole. The one in the CMS is the same construction, with error messages, a cache, and one more question for swapping a part in place.
First the rule becomes a tree. A node is a name, a sequence, a choice, or a repeat.
const lex = (rule) => rule.match(/[A-Za-z0-9_./-]+|[()|?*+]/g) ?? []
const parse = (rule) => {
const words = lex(rule)
let at = 0
const choice = () => {
const branches = [sequence()]
while (words[at] === '|') {
at += 1
branches.push(sequence())
}
return branches.length === 1 ? branches[0] : { choice: branches }
}
const sequence = () => {
const parts = []
while (at < words.length && words[at] !== ')' && words[at] !== '|') parts.push(part())
return parts.length === 1 ? parts[0] : { sequence: parts }
}
const part = () => {
let node
if (words[at] === '(') {
at += 1
node = choice()
at += 1
} else {
node = { name: words[at++] }
}
const mark = words[at]
if (mark === '?' || mark === '*' || mark === '+') {
at += 1
node = { repeat: node, optional: mark !== '+', many: mark !== '?' }
}
return node
}
return choice()
}Then the tree becomes a machine. This is Thompson’s construction, from 1968. Each node of the tree wires a few states together. A state has two kinds of move: free moves, which cost nothing, and moves it makes by reading a name.
const compile = (tree) => {
const states = []
const state = () => states.push({ free: [], on: {} }) - 1
const build = (node, from) => {
if (node.name) {
const to = state()
;(states[from].on[node.name] ??= []).push(to)
return to
}
if (node.sequence) return node.sequence.reduce((cursor, each) => build(each, cursor), from)
if (node.choice) {
const end = state()
for (const branch of node.choice) {
const start = state()
states[from].free.push(start)
states[build(branch, start)].free.push(end)
}
return end
}
const start = state()
const end = state()
states[from].free.push(start)
const done = build(node.repeat, start)
states[done].free.push(end)
if (node.many) states[done].free.push(start)
if (node.optional) states[from].free.push(end)
return end
}
const start = state()
return { states, start, final: build(tree, start) }
}To run the machine, keep the set of every state it could be in, and feed it the children one name at a time.
const reach = (machine, seed) => {
const live = new Set()
const todo = [...seed]
while (todo.length) {
const s = todo.pop()
if (live.has(s)) continue
live.add(s)
todo.push(...machine.states[s].free)
}
return live
}
const run = (machine, names) =>
names.reduce(
(live, name) => reach(machine, [...live].flatMap((s) => machine.states[s].on[name] ?? [])),
reach(machine, [machine.start]),
)Now the questions. There are four.
const shortest = (node) =>
node.name ? [node.name]
: node.sequence ? node.sequence.flatMap(shortest)
: node.choice ? node.choice.map(shortest).reduce((best, fill) => (fill.length < best.length ? fill : best))
: node.optional ? []
: shortest(node.repeat)
const grammar = (rule) => {
const tree = parse(rule)
const machine = compile(tree)
const names = [...new Set(lex(rule).filter((word) => !'()|?*+'.includes(word)))]
return {
accepts: (children) => run(machine, children).has(machine.final),
viable: (children) => run(machine, children).size > 0,
next: (children) => {
const out = new Set([...run(machine, children)].flatMap((s) => Object.keys(machine.states[s].on)))
return names.filter((name) => out.has(name))
},
fill: () => shortest(tree),
}
}accepts asks whether the children are a whole block. viable asks whether they could still become one. next asks what may come after them. fill is the shortest whole block there is.
Try it on the design system’s rule:
const block = grammar('(eyebrow | badge)? (heading subheading? lead? | lead)')
block.fill() // ["heading"]
block.next([]) // ["eyebrow","badge","heading","lead"]
block.next(['eyebrow']) // ["heading","lead"]
block.next(['heading']) // ["subheading","lead"]
block.next(['heading', 'lead']) // []
block.accepts(['eyebrow']) // false
block.viable(['eyebrow']) // true
block.viable(['lead', 'heading']) // falseviable is one line because of how the machine was built. Every state Thompson’s construction makes can still reach the end. So if any state is live, the children so far can still become a whole block.
What the editor asks
Every door in the editor is one of those questions.
A new block is born holding fill(). Place the design system’s title block and it arrives as one empty heading. Place this site’s and it arrives with all three parts, because its rule requires all three.
Add offers what next() allows. After an eyebrow the editor offers a heading or a lead, and it does not offer a badge. To add a part to a block that already has parts, the editor looks for the last position where the part still fits:
const place = (rule, children, name) => {
for (let at = children.length; at >= 0; at -= 1) {
if (rule.viable([...children.slice(0, at), name, ...children.slice(at)])) return at
}
return -1
}
place(block, ['heading'], 'eyebrow') // 0
place(block, ['heading'], 'lead') // 1
place(block, ['eyebrow', 'heading'], 'badge') // -1An eyebrow goes in front of the heading. A lead goes after it. A badge has nowhere to go while there is an eyebrow, so the editor never offers it.
Remove is allowed when what is left is still viable. On this site, taking the heading out from between the date and the lead is refused:
const post = grammar('eyebrow heading lead')
post.viable(['eyebrow', 'lead']) // false
post.viable(['eyebrow', 'heading']) // trueThe offers come in the rule’s order, not the alphabet’s. That is what names is for in next: a subheading is offered before a lead because the rule names it first.
None of this code knows what a title block is. It was never told about one. It works on the next component because it was never told about the last.
The template
The contract and the rule are data. The HTML belongs to the design, and it lives in a template beside each contract. This is the block’s:
<div class="mk-title-block" data-accent-content><%- typeof content !== 'undefined' ? content : '' %></div>One root and one hole. data-accent-content marks the hole, the place the children go. The block does not print a heading. The heading prints itself:
<%
var esc = require('/site/partials/utils/esc.js');
var assetData = (typeof cms !== 'undefined' && cms.asset && cms.asset.content) || {};
function val(name) {
if (typeof locals === 'object' && locals && locals[name] != null && locals[name] !== '') return locals[name];
return assetData[name];
}
var text = typeof val('text') === 'string' ? val('text') : '';
%><h1 class="mb-3"><%- esc(text) %></h1>One root tag, with the words inside it, escaped once. The words arrive under the field’s id, text, and they arrive one of two ways. Placed on a page, the element gets them as a plain local. Stored as a record of its own, it reads them from the record. A local wins when there is one.
A template has three duties. An element prints exactly one root tag. A container prints its root and marks its hole. And every class a template prints is one the design declared, never one it made up.
Another site on the same CMS prints its title block as a header element, with its own classes and a slightly different rule. Nothing in the editor knows which design it is drawing. It reads the rule, and the rule is all it reads.
What gets saved
When a block is placed, the CMS runs the templates once. This is the bake. It keeps what each element’s template printed, the root tag and its attributes, as the element’s shell. The words go inside the shell, and that is where the editor types them. The saved heading of a post on this site, trimmed:
{
"type": "accentElement",
"attrs": {
"typeId": "blog-post/heading",
"tag": "h1",
"attrs": { "class": "mb-3" },
"options": {}
},
"content": [{ "type": "text", "text": "What’s In A Name" }]
}The editor is TipTap, which sits on ProseMirror, and that is a ProseMirror node. ProseMirror has content expressions of its own, paragraph+ and the like, and compiles them to a machine the same way. The matcher above is the same idea moved up a level, from the editor’s nodes to a design’s components. It lives outside the editor so that a design can state its rules as data, and change them without anyone changing the editor.
This is also the one place where data and design sit in the same record. The type and the words are data. The tag and the class are the design’s. The live page prints the saved shell, so a change to heading.ejs reaches a saved page when its block is baked again, and not before. An atom is the exception. Its template runs at every print, which is why the date at the top of this page is always the post’s date.