The syntax
This is what spellbook-engine accepts and refuses, version 0.1 of the syntax. Every host reads a document the same way, because every host asks the same engine.
Tags
A tag is one of three forms:
{~ name attrs ~}
Opens a block. Its body runs to the next close.
{~~}
{~ name attrs /~}
- The first form opens a block. Its body runs to the next close tag.
- The close tag is written exactly as shown, with no space inside.
- The last form closes itself. It has no body.
Whitespace, new lines included, may sit anywhere between the parts of a tag. A name is one or more ASCII letters, digits or underscores.
Attributes
Attributes follow the name, separated by whitespace, in any order.
| Form | Example | Notes |
|---|---|---|
| Quoted pair | title="A 'quoted' bit" | Either quote. No escapes: the value ends at the next matching quote, and may hold ~}. |
| Bare pair | value=0.5 | Ends at whitespace or the end of the tag. Cannot hold ", ', =, <, > or a backtick. |
| Flag | striped | A key with no value. |
| Class | .hero, .md:flex | ASCII letters, digits, _, -, :. |
| Id | #main | ASCII letters, digits, _, -. |
A key starts with an ASCII letter, _, @ or :, and continues with ASCII letters, digits, _ or -. Whitespace may surround the =.
A bare value stops before the self-closing end, so this gives href the value /x:
{~ a href=/x/~}
Quote a value that ends in a slash.
Flags, classes and ids together
{~ card title="Pricing" footer="Billed monthly in CAD" .wide #pricing ~}
One block, one price.
{~~}
{~ accordion title="Why a block?" open ~}
So the words and the markup stay apart.
{~~}
How a host reads them
The engine keeps attributes in the order written, and offers three merged readings every host should share:
get(key): the last pair namedkey.classes(): the.nameshorthands first, then each word of everyclass="...", each class once.id():id="..."if written, else the first#name.
Code fences
A tag inside a fenced code block is text, not a tag. That is how this page shows tags without running them.
- A fence opens on a line whose first non-blank characters are three or more backticks, or three or more tildes. A backtick fence whose info string holds a backtick is not a fence.
- It closes on a line with the same character, at least as many of them, and nothing else.
- A fence left open runs to the end of the document.
```text
{~ alert ~}
This is text in a listing, not a block.
```
Inline code is not exempt. A tag between single backticks in a sentence is still a tag:
Write `{~~}` to close a block.
The engine reads it as a close tag, and with no block open the document is refused. Put literal syntax in a fence.
Nesting
A block with a body cannot sit inside another block. A self-closing block can.
{~ cards ~}
{~ tile name="Admin" /~}
{~ tile name="Read-Only" /~}
{~~}
That is the whole of nesting, on purpose. A block's body holds markdown and self-closing blocks; a tag that opens a body inside a body is refused with a line number, never rendered as broken output:
{~ card title="Outer" ~}
{~ alert type="info" ~}
A body inside a body.
{~~}
{~~}
line 2, column 1: block `alert` opens inside `card`: only a self-closing block may sit inside a block
What the engine gives back
The engine splits a document into its nodes in source order: markdown slices, exactly as written, and blocks. An empty slice is dropped. A block's body source is its body exactly as written, and its body nodes are the same body split. The engine shows the calls.