Comark syntax
A template is a Markdown file with YAML frontmatter. Comark adds four things to Markdown: block components, inline components, spans with attributes, and merge tags. The comark package parses all of it. The ir package then compiles it against two things: the kit, whose component schemas say what each component takes, and your data type, which every merge tag is resolved against.
This is one of the samples that ship with the Plain kit:
---
template: welcome
profile: default
subject: "Welcome to Example, {{first_name}}"
preheader: Your workspace is ready. Three things to set up first.
---
# Welcome, {{first_name}}
Your workspace **{{workspace}}** is ready. Most teams start with these three steps:
1. Invite your teammates
2. Connect a calendar
3. Pick a plan before {{trial_ends}}
::button{href="{{setup_url}}" label="Finish setting up"}
::
::image{src="{{cover_url}}" alt="An empty workspace waiting for its first project" width="496" caption="Your workspace, before the first project."}
::
::columns
:::column
### Guides
Short walkthroughs for every feature, most under five minutes.
:link[Read the guides]{href="https://example.com/guides"}
:::
:::column
### Help
Stuck on something? Reply to this email and a person will answer.
:link[Visit the help centre]{href="https://example.com/help"}
:::
::
::footer{note="You are receiving this because you created an account at Example. [Email settings](https://example.com/settings)"}
::
Top-level content is a stack of components. Each block component is one, and each run of loose Markdown between components goes into the kit's default component: section in Plain, letter in Quiet. Above, the heading, the paragraph and the list form one section. Components own their spacing, so a template never sets margins.
Know who decides what
Two layers check a template, and it helps to know which one you are talking to:
- The engine owns the syntax on this page: the component grammar, attributes, props,
:buttonand:link, spans, merge tags and the frontmatter core keys. It is the same for every kit. Raw HTML is always an error. - The kit owns the vocabulary: which components exist, their attributes and bindings, which Markdown blocks each one takes, the span classes, the extra frontmatter keys and the caps on buttons and links. Strikethrough, link titles and images in prose are parsed by the engine, but only components that opt in accept them.
So ::columns is valid in Plain and an unknown component in Quiet, and [text]{.teal} is a span in Quiet and an unknown span class in Plain. Components covers how a template uses a kit's schemas; Kits covers how to write them.
Start with frontmatter
Frontmatter is a YAML mapping between two --- lines, and it only counts when the first --- is the very first line of the file. The keys are described in Frontmatter.
A leading UTF-8 byte order mark is ignored and CRLF line endings are accepted everywhere. Invalid UTF-8 anywhere in the file is a parse error at its position (invalid utf-8), and a frontmatter block with no closing line is frontmatter: missing closing ---.
Open a block component
A block component opens with a line of two or more colons and a name, optionally followed by attributes. It closes with a line of exactly the same number of colons:
::columns
:::column
### Guides
Short walkthroughs for every feature.
:::
:::column
### Help
Reply to this email and a person will answer.
:::
::
- The name matches
[A-Za-z][A-Za-z0-9_-]*. Names and aliases are matched case-insensitively, so::Buttonis::button. - The opener line holds nothing but the colons, the name and the attributes (trailing whitespace is fine). Up to three leading spaces are allowed.
- The closer is a line of exactly the opener's colon count. A line with a different count does not close it.
- Nest a component inside another by giving it more colons (
:::columninside::columns). When two open components have the same count, the innermost one closes first. - A component can interrupt a paragraph, so you don't need a blank line before
::name. - A closer inside an open fenced code block is part of the code, and a component that is never closed ends at the end of the document.
- Components nest at most 32 deep (
components nested deeper than 32).
The parser accepts any name. The compiler then looks it up in the kit: a name the kit doesn't have is unknown component "callout", at the top level or nested, and a nested one the parent doesn't take is columns: only component column is allowed here, or column: component columns is not allowed here in a component that takes no children. What each kit offers is in Components.
Pass props
Attributes on the opener are one way to set a component's values. For longer values, put a props block at the start of the component instead. It has two forms, and both are read into the same set of keys as the attributes:
::button
---
href: "{{setup_url}}"
label: Finish setting up
---
::
::image
```yaml [props]
src: "{{cover_url}}"
alt: An empty workspace waiting for its first project
width: 320
```
::
- The
---form must be the first line after the opener. The fence form must be the component's first child, with the info string exactlyyaml [props]. - Props must be a YAML mapping. A YAML error is a parse error on its own line, prefixed
props:(for exampleprops: did not find expected ',' or ']'). A---block with no closing line isprops: missing closing ---, and using both forms isprops: given twice. - String props can hold merge tags, like attribute values. Integers (
width: 320) and booleans are plain YAML, and alistattribute also takes a YAML list. - A key given both as an attribute and as a prop is an error:
button: "label" set twice. - Bindings (
:key) go in the attribute list only.
Write attributes
An attribute list is {…} on one line:
attrs = "{" ws* (item ws*)* "}" ; "{{" never starts attributes
item = "." name | "#" name | [":"] key [ "=" value ]
name = [A-Za-z_][A-Za-z0-9_:-]*
value = '"' … '"' | "'" … "'" | bare
| Form | Example | Meaning |
|---|---|---|
key=value | width=320 | A bare value, up to the next space or }. |
key="value" | label="Pay {{total}}" | A quoted value. \" (or \') and \\ are the only escapes. |
key | headless | A flag: a boolean that is on. |
:key="path" | :invoice="invoice" | A binding: the value is a data path, not text. See Bind structured values. |
.class, #id | .muted | Classes are for spans. Components accept neither. |
Every non-binding value is text to the parser, so it can hold merge tags. The component's schema then gives each key a type (text, url, int, flag, enum, list or inline), described in Set attributes. Attributes never span lines, and a list is at most 4096 bytes. A list whose closing } is on the same line but which is invalid is a positioned parse error: duplicate attribute "width", duplicate #id, binding :src needs a value, expected a value after =, expected an attribute name. A key and its binding share a name, so steps="…" and :steps="…" in one list is duplicate attribute "steps".
A component reads only the keys its schema declares. Anything else, including an #id or a .class, is button: unknown attribute "target".
{ never closes on its line, for example because of a missing closing quote in ::button{href="https://example.com" label="Go}, is not a component at all. The line becomes text. In Plain that text lands in a section and compiles without a word, so the email shows the opener as a paragraph. In Quiet the errors that follow point at the content instead, typically letter: h1 is not allowed here. When a component seems to vanish, check the quotes on its opener.Leave slots alone
A line #name (no space after #) directly inside a component opens a slot. The parser supports slots, but the compiler reserves them for later: every slot is the compile error slots are reserved. # Heading, with a space, stays a heading.
Add inline components
Inline components sit inside a paragraph and come in three shapes: :name[label]{attrs}, :name[label] and :name{attrs}. The label is inline Markdown.
An inline component is recognised only when the character before the colon is the start of the line, whitespace, or punctuation other than :, and when the name is followed directly by [ or {. So 2:14 pm, Note:the and https://example.com are ordinary text.
The engine has two inline components, :button and :link, and a kit cannot add more (D40). The kit renders them and can cap how many a template uses. They are described in Actions and spans. Any other name is unknown inline component ":note".
Style text with spans
[text]{.class …} is a span: a run of inline Markdown with a style. It is a span only when ] is followed directly by {; otherwise [text] is handled by the normal link parser. The classes are whatever the kit declares under spans in kit.yaml. See Style text with spans.
Keep attributes off other elements
Comark can attach {attrs} directly after a link, image, emphasis, strong or code span, but the compiler accepts attributes only on spans and inline components. Anything else is attributes are only allowed on spans and inline components. Wrap the text in a span instead:
`{{order_id}}`{.small}
[`{{order_id}}`]{.small}
An invalid {…} after one of these elements stays literal text, so prose such as *no*{today's the day} still parses. And {{x}} right after a link is a merge tag, never an attribute list.
Insert merge tags
A merge tag is {{path}} or {{path | fallback}}:
Hi {{name | there}}, {{courier.first_name}} is on the way.
Your code is {{code | "not set"}}.
Write \{{name}} to show the braces.
- A path is dot-separated segments of
[a-z_][a-z0-9_]*: lower case, digits and underscores. Spaces around the path and the fallback are allowed. - The fallback is bare text, or quoted with
"…"when it contains|,}or leading spaces. A bare fallback may not contain{{: the tag becomes malformed and the text after it is read as a new tag. Use a quoted fallback for that. Inside a quoted fallback,\"and\\are escapes. - A tag never spans lines.
\{{is a literal{{.- Anything that starts with
{{but is not a valid tag ({{ Name }},{{name}) stays literal text and is reported as the warningmalformed merge tag "{{ Name }}". It does not fail the compile, so check warnings — see Read warnings.
Tags work in prose, headings, table cells, code spans (`{{order_id}}`), link destinations ([your order]({{order_url}})), autolinks, attribute values, props and frontmatter strings. The tag parser runs before emphasis, so underscores in a path never start italics.
What a path can name, the fallback rules, untyped data and how URL values are escaped are in Merge tags and data.
Build tables
GFM tables are allowed in components whose content allows table: Plain's section, and Quiet's breakdown, compare and table. A table anywhere else is column: table is not allowed here, with the component's name. Cells are inline Markdown: spans, strong, code spans and links all work, and column alignment (---:) reaches the kit's table block. Whether the first row renders as a header is the component's choice (table_header in its schema).
The table parser splits cells on every bare |, including one inside a merge tag. In a cell, write the fallback separator as \|:
| Item | Price |
| --- | ---: |
| For {{name \| there}} | {{total}} |
In a body row, a bare | splits the tag across two cells. The compiler warns malformed merge tag "{{name", and lttr lint then fails the HTML with html: contains "{{". In the header row, a bare | adds a column, so the delimiter row no longer matches and the lines are not a table at all: in Quiet's breakdown that is breakdown: paragraph is not allowed here and breakdown: expected a table. \| is accepted as the separator everywhere, not only in tables.
Know what is rejected
The parser reads all of CommonMark and GFM. The compiler turns down what has no place in an email, and asks the component about the rest. Each of these is a compile error at its position, shown here with the message from Plain's section or column:
| You wrote | Rule | Error |
|---|---|---|
| Raw HTML, inline or block | Always rejected. | raw html is not allowed |
A blockquote, a code block, a --- rule | Never compiled into a component. | section: blockquote is not allowed here, section: thematic break is not allowed here |
| A heading of a level the component doesn't take | content.headings | section: h4 is not allowed here |
| A list item with two paragraphs or a nested list | Always one paragraph per item. | section: list items must be one paragraph |
 alone in a paragraph | Needs content.allow: [image]. | column: images are not allowed here |
 inside a sentence | Always alone in its paragraph. | images must stand alone in their paragraph |
 | The alt text is required. | section: image alt text is required |
~~text~~ | Needs content.inline: [strike]. | footer: strikethrough is not allowed |
[text](url "title") | Needs content.inline: [link_title]. | section: link titles are not allowed |
Plain's section takes images and strikethrough, its column takes strikethrough, and neither shipped kit takes link titles. The opt-ins apply to the text of inline attributes too, gated by the component the attribute is on, so ::footer{note="~~free~~"} fails in Plain. Kit frontmatter keys of type inline accept none of them (frontmatter: strikethrough is not allowed).
--- directly under a line of text is a CommonMark setext heading, not a rule: the text becomes an h2. Plain's section takes h2, so the email silently gets a heading. Quiet's letter doesn't (letter: h2 is not allowed here). Leave a blank line before --- if you meant frontmatter or props.Next steps
- Frontmatter for the header keys.
- Components for using a kit's components.
- Compile errors for reading what the compiler reports.