---
url: https://zeokku.github.io/zamn/guide/introduction.md
---
# Introduction
zamn is a static way to write HTML. A tag is its name, classes and ids are `.class` and `#id`, and an element's children go in a `{ }` block. There are no closing tags, and nothing to keep in sync.
```zamn
article.post#intro {
h2.title Hello
p {
| Written in
|
a(href="https://github.com/zeokku/zamn") zamn
| .
}
}
```
```html format
```
The HTML is shown formatted, here and throughout the docs; the compiler writes it on one line.
## Static, on purpose
A zamn template is markup. Logic, loops and composition belong to your framework: `li(v-for="item in items")`, `p(v-if="user")`, components. Attribute values are strings, as in HTML, and expressions go in bindings (`:title="t"`, `@click="go"`) or `= expr`, which writes `{{ expr }}`. Text is escaped, so `p a < b` shows `a < b`.
Since there is nothing to run, a template compiles to the same HTML every time, in one pass, with a [source map](../reference/api#compile). Tooling can read it without executing anything: the [Vue language tools](../ecosystem/typescript), [ESLint](../ecosystem/eslint) and [Prettier](../ecosystem/prettier) all work on zamn templates.
## Why another syntax
zamn was originally inspired as a modern [pug](https://pugjs.org) replacement: compact templates, but without indentation quirks, with a clearer syntax, modern maintained code and performance. Its syntax for tags, classes, ids and attributes comes from pug's.
* **Less to read.** No `` at the bottom of the screen to match up with the top: a block ends with a `}`.
* **Braces, not indentation.** Pug templates are commonly criticized for indentation-based nesting, which gets hard to read and maintain. That's why zamn nests with `{ }` blocks instead, just like JavaScript or SCSS. Indentation is for the eye, and zamn warns about a line indented like a child when it isn't one.
* **Less to write.** For people, and for coding agents: the same page takes fewer tokens in zamn than in HTML. See [Writing zamn with AI agents](../ai/).
* **Nothing hidden.** What you write is what you get: there's no runtime and no logic in the template.
## Where to go next
* [Getting started](./getting-started): install it, compile a file.
* [Syntax](./syntax/elements): the whole language, one page per topic.
* [Ecosystem](../ecosystem/overview): Vite, TypeScript, ESLint, Prettier and VS Code for Vue projects.
* [Playground](../playground): try it in the browser.
---
---
url: https://zeokku.github.io/zamn/guide/getting-started.md
---
# Getting started
## Try it
The quickest way is the [playground](../playground): type zamn on the left and see the HTML on the right.
## Install
::: code-group
```sh [bun]
bun add -d zamn
```
```sh [npm]
npm install -D zamn
```
```sh [pnpm]
pnpm add -D zamn
```
```sh [cargo]
cargo install zamn
```
:::
The npm package is the compiler built to WebAssembly, so it has no native dependencies and works in Node, Bun, Deno and the browser. `cargo install` gives you the `zamn` command line tool.
## A first template
Save this as `page.zamn`:
```zamn
doctype html
html(lang="en") {
head {
meta(charset="utf-8")
title My page
}
body {
h1 Hello
p.lead Plain HTML, without the angle brackets.
}
}
```
Compile it from the command line:
```sh
zamn page.zamn -o page.html
```
`page.html` now holds this page, shown formatted:
```html format
My page
Hello
Plain HTML, without the angle brackets.
```
The compiler writes it on one line, with no whitespace between tags. Whitespace you want in the page is written explicitly; see [Text](./syntax/text). The docs show HTML formatted like this, except where the exact whitespace is the point.
## From JavaScript
```ts
import { compile } from "zamn";
const source = await Bun.file("page.zamn").text();
const { code, map, warnings } = compile(source, { filename: "page.zamn", sourceMap: true });
```
`compile` throws a `ZamnError` that lists every error in the template, and returns warnings alongside the HTML. `lex` and `parse` never throw: they return the tokens or the syntax tree together with diagnostics. See the [JavaScript API](../reference/api).
## In a Vue project
`` works in single-file components once Vite knows how to compile it. The [ecosystem overview](../ecosystem/overview) sets up the build, type checking, linting, formatting and editor support, one step at a time.
```vue
.greetings {
h1.green= msg
h3 You did it!
}
```
## Errors
A template with errors is not compiled. Each problem names its code, the place and usually a hint:
```zamn error=JS_EXPRESSION
nav {
a(href=base + "/docs") Docs
}
```
```text
page.zamn:2:10: error[JS_EXPRESSION]: JavaScript expressions are not supported in attribute values
hint: zamn has no JavaScript; quote the value, or write a binding such as `:href` for your framework
```
Warnings, such as a line indented as if it were a child when it isn't, are printed the same way, as `warning[CODE]`, and the template still compiles. All codes are listed under [Diagnostics](../reference/diagnostics).
---
---
url: https://zeokku.github.io/zamn/guide/syntax/elements.md
---
# Elements
## Tags
A statement that starts with a name is an element. Its children go in a `{ }` block after it:
```zamn
ul {
li One
li Two
}
```
```html format
One
Two
```
Text after the name and a space is the element's content. See [Text](./text). Blocks are explained in [Brace blocks](./brace-blocks).
A tag name may contain letters, digits, `_`, `-` and `:`, so custom elements, components and namespaced tags all work:
```zamn
my-card {
my-button Go
svg:circle(r="4")
}
```
```html format
Go
```
A tag can't hold a `.`: that starts a class. `Form.Input` is the tag `Form` with the class `Input`.
## The implicit `div`
A statement that starts with a class or an id is a `div`:
```zamn
.card {
#title Hello
}
```
```html
Hello
```
## Block expansion
`tag: child` puts a single child on the same line. It nests as deep as you like:
```zamn
ul {
li: a(href="/") Home
li: a(href="/about"): b About
}
```
```html format
```
The space after the `:` is required; `svg:path` is a tag name.
## Void elements
The output is always HTML5. `area`, `base`, `br`, `col`, `embed`, `hr`, `img`, `input`, `link`, `meta`, `param`, `source`, `track` and `wbr` are written without a closing tag or a `/`, and every other element gets its closing tag, even when it is empty:
```zamn
img(src="/logo.png" alt="Logo")
br
icon-star
```
```html format
```
Giving a void element content is an error (`SELF_CLOSING_CONTENT`).
---
---
url: https://zeokku.github.io/zamn/guide/syntax/brace-blocks.md
---
# Brace blocks
An element holds its children in `{ }`. It is the only way to nest: a block visibly starts and ends, so long templates stay easy to follow, and indentation is free to show the structure the way you like.
```zamn
div {
.another-div {
button(@click="go") Text
p= message
}
}
```
```html format
{{ message }}
```
## The rules
* **A `{` straight after the tag head** opens a block: after the tag and its classes, ids and attributes, as in `section.main(role="main") {`. The space before it is optional.
* **The block closes at its matching `}`**, on the same line or on any line after it.
* **`p {}`** (or `p { }`) is an empty block: ``.
* **Each child is a statement**, and a statement ends at:
* the end of its line;
* a `}`, which closes the block it is in;
* the `}` that ends its own block (or its [`|{ }` text](./text#text-blocks)), after which another statement may follow on the same line.
So a block can open and close on one line, and hold several children there:
```zamn
ul.nav { li { a(href="/") Home } li { a(href="/about") About } }
.card { .card-body { h2 Title }}
```
```html format
```
`}}` closes two blocks, as in `.card` above, unless it ends a [`{{ }}` mustache](./interpolation#inside-text) in text.
## Text ends its line
Text and `= expr` run to the end of the line, or to the `}` that closes the block they are in. The only way to start another child after text is a new line:
```zamn
p { b bold i italic }
p {
b bold
i italic
}
```
```html format
bold i italic
bolditalic
```
In `= expr`, braces and quoted strings are counted, so an object literal passes through:
```zamn
p {
span= ok ? { a: 1 }.a : 0
}
```
```html
{{ ok ? { a: 1 }.a : 0 }}
```
## Indentation
Indentation means nothing to zamn: the braces alone decide what holds what. Indent with spaces or tabs, by any amount, or not at all:
```zamn
section {
h2 Title
p {
| Text
}
}
```
```html format
Title
Text
```
[Prettier](../../ecosystem/prettier) indents every block for you.
Since indentation is not structure, a line indented as if it were a child is a sibling. zamn warns about it (`MISLEADING_INDENTATION`) when a statement is indented deeper than the statement before it in the same block, and that statement left no block open:
```zamn warning=MISLEADING_INDENTATION
p Some text
b bold
```
```html format
Some text
bold
```
The `b` is not inside the `p`: put it in braces (`p { | Some text` and `b bold` on the lines below), or indent it as a sibling. It is a warning, not an error: the template still compiles. The first line of a block, continued attribute lists, [`|{ }` text](./text#text-blocks), [script and style content](./script-style) and comments can be indented as you like.
## Braces in text
Only a `{` straight after the tag head opens a block. In text, `{{ ... }}` is a [mustache](./interpolation#inside-text), and every other brace is written `\{` or `\}`:
```zamn
p some \{ text \}
| \{ more text \}
p {{ message }}
```
```html format
some { text }
{ more text }
{{ message }}
```
`{{` never opens a block, so `p {{ message }}` is text, as Vue expects. `p {b}` is a `p` holding a `` element; `p \{b\}` is the text `{b}`.
A `{` left bare in text is an error (`UNESCAPED_BRACE`), and a bare `}` closes the block, so a brace in text never goes unnoticed.
## Errors
* A `{` that is never closed: `UNCLOSED_BRACE`.
* A `}` with no `{` to close: `UNMATCHED_BRACE`.
* A bare `{` in text: `UNESCAPED_BRACE`.
See [Diagnostics](../../reference/diagnostics#blocks).
---
---
url: https://zeokku.github.io/zamn/guide/syntax/classes-ids.md
---
# Classes and ids
`.name` adds a class and `#name` sets the id. Write as many as you need, straight after the tag, in any order:
```zamn
button.btn.btn-primary#save Save
```
```html
```
Without a tag, the element is a `div`:
```zamn
#app.dark
```
```html
```
## Merging with `class`
Classes from `.name` and from `class="..."` attributes are merged into one `class` attribute, in the order they are written, and it always comes first:
```zamn
a.btn(href="/" class="big").primary Home
```
```html
Home
```
An empty `class=""` adds nothing.
## Utility classes
Class names can hold what utility frameworks such as Tailwind put in them, so they work as shorthands too:
```zamn
.grid.grid-cols-1.gap-6.sm:grid-cols-2.dark:bg-gray-900
.w-1/2.px-2.5.md:flex.hover:bg-sky-700.!mt-0
.[&>*]:p-2.h-[calc(100%-2rem)].bg-(--brand).@container.*:rounded
```
```html format
```
After the `.`, a class name may hold:
* letters, digits, `_`, `-`, `@`, `*` and `%`;
* `:` and `/` when another class character follows, so in `li.active: a Home` the `: ` is still [block expansion](./elements#block-expansion);
* `.` when a digit follows (`px-2.5`); any other `.` starts the next class;
* `!` when no `=` follows;
* a `[...]` with no whitespace or braces inside (quotes are fine: `content-['*']`);
* a `(...)` straight after a `-` (`bg-(--brand)`); any other `(` starts the attributes.
A class name must contain at least one letter or `_`: `.-x`, `._y` and `.col-2` are fine, `.5` is an error (`INVALID_CLASS_NAME`). Shorthand classes are written to the HTML as they are, with only `"` escaped. A name with whitespace or braces in it goes in a `class="..."` attribute.
## Valid ids
An id holds letters, digits, `_` and `-`. A `#` with no name after it is an error (`INVALID_ID`).
`id` can appear only once per element: `p#a(id="b")` is an error (`DUPLICATE_ATTRIBUTE`).
---
---
url: https://zeokku.github.io/zamn/guide/syntax/attributes.md
---
# Attributes
Attributes go in parentheses after the tag, its classes and ids:
```zamn
a(href="/docs" target="_blank") Docs
```
```html
Docs
```
Separate them with spaces or with commas, as you like:
```zamn
a(href="/docs", target="_blank") Docs
```
```html
Docs
```
## Values
A value is one of:
| Value | Example | Output |
|---|---|---|
| a string in `"`, `'` or `` ` `` | `title='say "hi"'` | `title="say "hi""` |
| a number | `tabindex=-1` | `tabindex="-1"` |
| unquoted, as in HTML: anything but whitespace, `"`, `'`, `` ` ``, `=`, `<`, `>`, `,` and `)` | `href=/docs/`, `target=_blank` | `href="/docs/"`, `target="_blank"` |
| an object, for `style` | `style={color: red, fontSize: 12px}` | `style="color:red;font-size:12px;"` |
| `true`, or no value | `disabled`, `disabled=true` | `disabled` |
| `false`, `null` or `undefined` | `hidden=false` | the attribute is left out |
```zamn
input(type="checkbox" checked hidden=false tabindex=-1)
```
```html
```
A boolean attribute is always written as just its name, the way HTML and Vue expect it.
Quoted strings take JavaScript escapes: `title="it\'s"` is `it's`, `"\u00e9"` is `é`. An empty `style=""` (or `style={}`) is left out.
A comma or `)` ends an unquoted value, as they separate and close the attributes. Quote a value that holds one, or any of the characters HTML doesn't allow (`INVALID_ATTRIBUTE_VALUE`):
```zamn
a(href=/docs/, target=_blank) Docs
a(href="/search?q=zamn") Search
```
```html format
DocsSearch
```
## Style objects
`style={...}` is written as CSS, `key:value;` for each entry:
* a key may be quoted or bare, and a bare key may hold `-`;
* a camelCase key becomes kebab-case, as in React: `fontSize` is `font-size`, `WebkitLineClamp` is `-webkit-line-clamp`, `msFlex` is `-ms-flex`;
* a custom property (`--accent`) is kept as written;
* a value is a quoted string, or bare text up to the next `,` or `}`; brackets and quoted parts inside it are counted, so `rgb(0, 128, 255)` and `url('a,b.png')` need no quotes.
```zamn
p(style={color: red, fontSize: 12px, --accent: rgb(0, 128, 255), 'line-height': 1.5}) Red
```
```html format
Red
```
This is for the static `style` attribute only: a `:style` binding is passed to your framework as written.
## Escaping
Values are HTML-escaped: `&`, `<`, `>` and `"` become entities. Use `!=` to write a value as it is:
```zamn
p(title="a < b" data-html!="bold")
```
```html
```
## No expressions
A value is never evaluated: there is no JavaScript in zamn. Anything that looks like an expression (`href=url + "/x"`, `class=['a', 'b']`, `` title=`${x}` ``) is an error (`JS_EXPRESSION`):
```zamn error=JS_EXPRESSION
a(href=base + "/docs") Docs
```
In Vue, write a binding instead: its value is a string to zamn and an expression to Vue.
```zamn
a(:href="base + '/docs'") Docs
```
```html
Docs
```
A binding (`:x`, `@x`, `#x`, `.x`, `v-*`) may also go without quotes, as HTML allows. A value in `{ }`, `[ ]` or `( )` is copied as written, spaces and all:
```zamn
router-link(:to=/about :class={ active: onAbout } @click=go()) About
```
```html format
About
```
The value ends at its closing bracket, and whatever follows is the next attribute. Quote a value that goes on after it:
```zamn
li(v-for="(item, i) in items")
li(v-for=(item, i) in items)
```
```html format
```
## Names
Names can hold almost anything but spaces, `=`, `,` and `)`, so framework syntax works as written:
```zamn
my-input(
v-model.trim="name"
:label="t('name')"
@update:model-value="save"
#prefix="{ icon }"
)
```
```html format
```
Quote a name to use other characters: `("odd name"="1")`. Each name may appear only once per element, except `class` (`DUPLICATE_ATTRIBUTE`).
## Over several lines
The parentheses may span lines. A value may too, and its line breaks are kept:
```zamn
div(
:class="{
active: isActive
}"
@click="select(item)"
)
```
```html format
```
A `(` without its `)` is an error (`NO_END_BRACKET`), as is a `=` with no value (`MISSING_ATTRIBUTE_VALUE`).
---
---
url: https://zeokku.github.io/zamn/guide/syntax/text.md
---
# Text
## Inline
Everything after the tag and one space is text:
```zamn
p Hello, world.
```
```html
Hello, world.
```
Piped text and text blocks are statements, and an element takes them as it takes any other child, after a `:`. These three are identical:
```zamn
div some text
div: | some text
div: |{ some text }
```
```html format
some text
some text
some text
```
## Escaping
Text is HTML-escaped: `<` and `>` become `<` and `>`, and `&` becomes `&`, unless it starts a character reference such as `→`, `{` or ``, which passes through:
```zamn
p Ready? Go → Tom & Jerry
```
```html
Ready? <b>Go</b> → Tom & Jerry
```
So text shows tags as text, and you write elements as elements: `p Ready? #{b Go}` (see [inline elements](#inline-elements)). The same goes for `pre`. There is no way to write raw HTML in text; for HTML that comes from data, use your framework, such as Vue's `v-html`.
Not escaped: the content of [`script` and `style`](./script-style), [mustaches and `= expr`](./interpolation), and [comments](./comments).
## Piped text
A statement that is only text starts with `|`, anywhere an element could be. Consecutive `|` lines are joined as they are, with nothing between them; a bare `|` is the space between two lines (see [Whitespace](#whitespace)):
```zamn
p {
| The first line
|
| and the second.
}
```
```html
The first line and the second.
```
A `|` means this only where a statement starts. After a tag, it is text like any other character:
```zamn
p | not piped
```
```html
| not piped
```
Text that begins with a mustache or an inline element needs the `|` too: a statement that starts with `{{` or `#{` is an error (`UNEXPECTED_TEXT`).
```zamn
p {
| {{ greeting }}, #{b world}
}
```
```html
{{ greeting }}, world
```
## Whitespace
Text is trimmed at both ends: the whitespace after the tag, after `|` and after the tag of an inline element is left out, and so is whitespace at the end of a line, everywhere. The output has no whitespace between elements or lines of text unless you write it, and a `|` on its own is one space. That's how a space between two lines is written:
```zamn
p {
b this
|
| is
|
u cool
}
```
```html
this is cool
```
## Text blocks
`|{ ... }` holds text that may span lines. On one line it is trimmed. Over several lines:
* a blank first and last line are dropped, so the text can start on the line after the `{` and end on the line before the `}`;
* the indentation the lines have in common is stripped, and deeper indentation is kept;
* the lines are joined with line breaks.
```zamn
pre: |{
function go() \{
return a < b;
\}
}
```
```html
function go() {
return a < b;
}
```
It can also stand inside a block, among other children, and holds [inline elements](#inline-elements):
```zamn
p {
|{
A block of text
over two lines, with #{em inline} elements.
}
}
```
```html
A block of text
over two lines, with inline elements.
```
Whitespace between the `|` and the `{` is optional: `|{ … }` and `| { … }` are the same. That is why piped text that starts with a brace is written `| \{ …`. After a tag, a text block needs its `:` like any other child: `pre |{` is the text `|` followed by a bare `{`, an error (`UNESCAPED_BRACE`) whose hint says to write `pre: |{`.
## Escapes
* `\{` and `\}` are literal braces. Any other brace in text is either a [mustache](./interpolation#inside-text) (`{{ }}`), a bare `{` (an error, `UNESCAPED_BRACE`) or a `}` that closes the block. See [Braces in text](./brace-blocks#braces-in-text).
* `\#{` is a literal `#{`, and `\#[` a literal `#[`.
* Any other backslash is just a backslash.
```zamn
p Write \#{ to start an inline element.
p C:\temp
```
```html format
Write #{ to start an inline element.
C:\temp
```
## Inline elements
`#{...}` puts an element in the middle of text. It holds exactly one statement, so it takes everything an element takes: classes, attributes, `= expr`, `:` expansion, and its own text, which runs to the `}`:
```zamn
p Read the #{a(href="/docs") docs} or #{em: b ask}.
```
```html
```
It works in piped text and in `|{ }` blocks too, and inline elements nest:
```zamn
p { | some #{b biba #{i boba}} text }
```
```html
some biba boba text
```
## Text outside elements
Piped text works at the top level of a template as well:
```zamn
| Hello,
|
b world
```
```html
Hello, world
```
---
---
url: https://zeokku.github.io/zamn/guide/syntax/script-style.md
---
# Scripts and styles
`script` and `style` hold raw content. The tag's line ends the head, the lines below are the content, and a line that holds only `/script` (or `/style`) ends it:
```zamn
script
if (a < b && ready) {
go();
}
/script
style
a > b { color: red }
/style
```
```html
```
The content is copied as it is:
* it is not parsed: braces, `#{`, `{{ }}` and backslashes are just characters;
* it is never escaped;
* as in [`|{ }` text](./text#text-blocks), a blank first and last line are dropped, and the indentation the lines have in common is stripped, keeping deeper indentation.
They work inside a block like any other element, and the `/script` line may be indented as you like:
```zamn
body {
p Hello
script
console.log("loaded")
/script
}
```
```html format
Hello
```
## With `src`
A script with `src` (or `:src`, `v-bind:src`) has no content, since browsers ignore it, and no closing line:
```zamn
script(type="module" src="/main.js")
p Next
```
```html format
Next
```
## Errors
* No closing line before the end of the file is `UNCLOSED_RAW`, reported at the `script` line, with the hint "end it with `/script` on its own line".
* A `/script` after a script with `src`, or a `/tag` line for any other tag, is `UNMATCHED_CLOSE`.
* `script` and `style` take no `{ }` block, `|{ }` text or text on their own line. Each is an error, with a hint pointing to `/script` content.
```zamn error=UNCLOSED_RAW
script
go()
```
## `pre` and other elements
Only `script` and `style` hold raw content. `pre` is an ordinary element, whose text is escaped and may hold [inline elements](./text#inline-elements). Write multi-line text in it with `pre: |{ ... }`; see [Text blocks](./text#text-blocks).
---
---
url: https://zeokku.github.io/zamn/guide/syntax/interpolation.md
---
# Interpolation
zamn doesn't evaluate anything, but it writes interpolation for the framework that will. `= expr` becomes `{{ expr }}`:
```zamn
h1= title
p {
= greeting
|
= name
}
```
```html format
{{ title }}
{{ greeting }} {{ name }}
```
The expression runs to the end of the line, or to the `}` that closes the block it is in, and is copied as it is, without escaping. Braces and quoted strings in it are counted, so `p { span= { a: 1 }.a }` works. zamn never parses it otherwise, so any expression your framework accepts works: `p= items.length > 0 ? "some" : "none"`.
`=` with nothing after it is an error (`MISSING_EXPRESSION`).
## Inside text
`{{ ... }}` in text is a mustache: it reaches the framework untouched, and is not escaped like the text around it:
```zamn
p Hello {{ user.name }}, you have #{strong= count} messages.
p {{ a < b && c ? "yes" : "no" }}
```
```html format
Hello {{ user.name }}, you have
{{ count }}
messages.
{{ a < b && c ? "yes" : "no" }}
```
A mustache must close within its text; one that doesn't is an error (`UNCLOSED_INTERPOLATION`). A statement can't start with `{{`: write `| {{ name }}`, or `= name`.
## Other delimiters
`{{` and `}}` are what Vue (and Angular, Handlebars and others) use. For another framework, pass the `interpolation` option to [`compile`](../../reference/api#compile):
```ts
compile("p= user", { interpolation: ["${", "}"] });
//
${ user }
```
It changes what `= expr` writes; mustaches in text are copied as written.
## In attributes
Attribute values are never interpolated. In Vue, bind them instead:
```zamn
img(:src="user.avatar" :alt="`Avatar of ${user.name}`")
```
```html
```
---
---
url: https://zeokku.github.io/zamn/guide/syntax/comments.md
---
# Comments
`//` is a comment for the template's readers: it is left out of the HTML. `//!` is an HTML comment: it is written to the output. Both run to the end of their line.
```zamn
// Only people reading the template see this.
//! Everyone reading the page source sees this.
p Hello
```
```html format
Hello
```
Everything after the marker is copied as written, including the space after it.
## Block comments
`/* ... */` is left out of the HTML, and `/*! ... */` is written as an HTML comment. A block comment can span lines and ends at the first `*/`; block comments don't nest. Its content is not parsed, so it can hold anything, including lines that would be errors:
```zamn
/*
Not ready yet:
a(href=base + "/docs") Docs
*/
/*! Built by zamn */
p Done
```
```html format
Done
```
A block comment goes wherever a statement can start: on a line of its own, after a `{`, or after a child that ends with `}`:
```zamn
div { /* the title */ h2 { | Title } /* the body */ p Body }
```
```html format
Title
Body
```
An unclosed block comment is an error (`UNCLOSED_COMMENT`).
## In text
Inside text, `//` and `/*` are just text, so links and paths need nothing special:
```zamn
a(href="https://zamn.dev") https://zamn.dev
p Globs like src/*.ts stay as written.
```
```html format
https://zamn.dev
Globs like src/*.ts stay as written.
```
Comments are not escaped: what you write after `//!` or inside `/*! */` reaches the HTML as it is.
## In editors and linters
"Toggle Line Comment" in [VS Code](../../ecosystem/vscode) writes `//`, so commenting out a line never puts it into the page. ESLint directives work as `//` comments in a Vue template:
```zamn
// eslint-disable-next-line vue/no-v-html
div(v-html="content")
```
---
---
url: https://zeokku.github.io/zamn/guide/syntax/doctypes.md
---
# Doctype
`doctype html` writes the HTML5 doctype, and goes at the top of a full page:
```zamn
doctype html
html {
body {
input(type="checkbox" checked)
br
}
}
```
```html format
```
`doctype X` writes ``, whatever `X` is:
```zamn
doctype html PUBLIC "-//W3C//DTD HTML 4.01//EN"
```
```html
```
A `doctype` with nothing after it is an error (`MISSING_DOCTYPE`): write `doctype html`, or leave the line out.
The doctype changes nothing else. The output is always HTML5, with or without one: void elements are written ` ` and boolean attributes `checked`. A component template, such as a Vue ``, has no doctype.
---
---
url: https://zeokku.github.io/zamn/ecosystem/overview.md
---
# Ecosystem
zamn comes with everything a Vue project expects of its templates. Each piece is a
separate package, so add only what you use.
| Package | What it does | Page |
|---|---|---|
| `zamn` | the compiler: Vite uses it to build `` | [Vite and Vue](./vite) |
| `vue-language-plugin-zamn` | type checking with `vue-tsc`, plus completion, hover, go to definition and rename in the editor | [TypeScript](./typescript) |
| `eslint-plugin-vue-zamn` | lets eslint-plugin-vue lint zamn templates, and reports zamn's syntax errors | [ESLint](./eslint) |
| `vue-eslint-parser-template-tokenizer-zamn` | the part of the above that reads templates; set up for you by `eslint-plugin-vue-zamn` | [ESLint](./eslint#by-hand) |
| `prettier-plugin-zamn` | formats `.zamn` files and `` | [Prettier](./prettier) |
| zamn for VS Code | syntax highlighting and folding in `.zamn` files and Vue components | [VS Code](./vscode) |
## Set up a Vue project
Starting from a Vue + Vite project (`bun create vue`, say), these six steps are the whole setup. Each links to its own page, with the details and options.
### 1. Build
```sh
bun add -d zamn
```
```ts
// vite.config.ts
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { compile } from "zamn";
const zamn = {
render(source: string, { filename }: { filename: string }, done: (error: unknown, html?: string) => void) {
try {
done(null, compile(source, { filename }).code);
} catch (error) {
done(error);
}
},
};
export default defineConfig({
plugins: [vue({ template: { preprocessCustomRequire: (lang) => (lang === "zamn" ? zamn : undefined) } })],
});
```
Full setup and options: [Vite and Vue](./vite).
### 2. Write a template
```vue
.greetings {
h1.green= msg
h3 You did it!
}
```
### 3. Type check
```sh
bun add -d vue-language-plugin-zamn
```
```jsonc
// tsconfig.app.json
{
"vueCompilerOptions": { "plugins": ["vue-language-plugin-zamn"] }
}
```
The Vue - Official extension picks it up too. Full setup and options: [TypeScript](./typescript).
### 4. Lint
```sh
bun add -d eslint-plugin-vue-zamn
```
```js
// eslint.config.js
import vue from "eslint-plugin-vue";
import vueZamn from "eslint-plugin-vue-zamn";
export default [
...vue.configs["flat/recommended"],
...vueZamn.configs.recommended,
];
```
Full setup and options: [ESLint](./eslint).
### 5. Format
```sh
bun add -d prettier prettier-plugin-zamn
```
```json
// .prettierrc
{ "plugins": ["prettier-plugin-zamn"] }
```
Full setup and options: [Prettier](./prettier).
### 6. Highlight
```sh
code --install-extension zeokku.zamn-vscode
```
Full setup and options: [VS Code](./vscode).
When you're done, the scripts of a fresh Vue project all understand zamn:
| Script | What reads the zamn templates |
|---|---|
| `dev`, `build` | Vite, through `zamn` |
| `type-check` | `vue-tsc`, through `vue-language-plugin-zamn` |
| `lint` | ESLint and eslint-plugin-vue, through `eslint-plugin-vue-zamn` |
| `format` | Prettier, through `prettier-plugin-zamn` |
The [example app](https://github.com/zeokku/zamn/tree/main/example) in the repository
is Vue's starter app with every template in zamn and all of this set up.
## Versions
| Package | Needs |
|---|---|
| `vue-language-plugin-zamn` | `@vue/language-core` 3.3 or later (Vue - Official and `vue-tsc` 3.3), Node 22.12 or later |
| `eslint-plugin-vue-zamn` | ESLint 9 or later (flat config), eslint-plugin-vue 10, vue-eslint-parser 10.4 or later, Node 22.12 or later |
| `prettier-plugin-zamn` | Prettier 3 |
| zamn for VS Code | VS Code 1.100 or later |
The Node versions come from `require()` of ES modules, which Vue's language tools
and vue-eslint-parser use to load plugins.
---
---
url: https://zeokku.github.io/zamn/ecosystem/vite.md
---
# Vite and Vue
`@vitejs/plugin-vue` compiles `` with a preprocessor it asks you for by name. Give it zamn:
```sh
bun add -d zamn
```
```ts
// vite.config.ts
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { compile } from "zamn";
// What Vue's compiler asks of a template preprocessor: the template in, HTML
// out through a callback.
const zamn = {
render(
source: string,
options: { filename: string },
done: (error: unknown, html?: string) => void,
) {
try {
done(null, compile(source, { filename: options.filename }).code);
} catch (error) {
done(error);
}
},
};
export default defineConfig({
plugins: [
vue({
template: {
// Compiles .
preprocessCustomRequire: (lang) => (lang === "zamn" ? zamn : undefined),
},
}),
],
});
```
Now any component can use it:
```vue
button.counter(type="button" @click="count++") {
| Count:
|
= count
}
```
## Errors
`compile` throws a [`ZamnError`](../reference/api#zamnerror) with `id` and `loc` set, which is what Vite prints, so the overlay points at the file and line of the first problem. Its message lists how many more there are. Warnings don't stop the build; `compile` returns them in `warnings`, and [ESLint](./eslint) reports them in the editor.
## Without Vue
For plain HTML pages, call [`compile`](../reference/api#compile) from your build script, or use the [CLI](../reference/cli).
---
---
url: https://zeokku.github.io/zamn/ecosystem/typescript.md
---
# TypeScript
`vue-language-plugin-zamn` teaches the [Vue language tools](https://github.com/vuejs/language-tools)
to read zamn templates. With it, `` is type checked by
`vue-tsc`, and the Vue - Official extension gives you completion, hover, go to
definition and rename in it, as in an HTML template.
```sh
bun add -d vue-language-plugin-zamn
```
```jsonc
// tsconfig.json (tsconfig.app.json in a create-vue project)
{
"vueCompilerOptions": {
"plugins": ["vue-language-plugin-zamn"]
}
}
```
```vue
ul.list {
li(v-for="item in items" :key="item.id")= item.nmae
}
```
```sh
vue-tsc --noEmit
```
```text
List.vue(7,50): error TS2339: Property 'nmae' does not exist on type '{ id: number; name: string; }'.
```
The error points at the zamn source: line 7 is the `li` line.
This plugin only teaches the language tools to read the template. Building it is up
to [Vite](./vite).
## Requirements
`@vue/language-core` 3.3 or later, which ships with Vue - Official and `vue-tsc` 3.3,
and Node 22.12 or later.
## How it works
The template is turned into HTML that Vue's compiler parses, and every position in the result is moved back onto the zamn source. That HTML is built from [`parse`](../reference/api#parse), not from `compile`, so a template with errors is still checked wherever it can be read, and expressions keep their exact positions. zamn's own errors are reported as template errors, and its warnings as warnings.
## Limits
* An implicit `div` (`.card`, `#app`) has no tag name to point at. Its classes and
ids map to where they are written.
* In an attribute value written with string escapes (`title="it\'s"`), positions
are only exact at the start of the value.
---
---
url: https://zeokku.github.io/zamn/ecosystem/eslint.md
---
# ESLint
`eslint-plugin-vue-zamn` lets [eslint-plugin-vue](https://eslint.vuejs.org) lint zamn templates. It has a config that teaches ESLint to read `` and turns off the rules that can't apply there, and four rules of its own.
```sh
bun add -d eslint-plugin-vue-zamn
```
```js
// eslint.config.js
import vue from "eslint-plugin-vue";
import vueZamn from "eslint-plugin-vue-zamn";
export default [
...vue.configs["flat/recommended"],
// After the configs of eslint-plugin-vue, and after anything else that
// turns their rules on.
...vueZamn.configs.recommended,
{
files: ["**/*.vue"],
rules: {
"vue-zamn/component-name-in-template-casing": ["error", "kebab-case"],
},
},
];
```
Needs ESLint 9 or later (flat config), eslint-plugin-vue 10, vue-eslint-parser 10.4 or later, and Node 22.12 or later.
With `@vue/eslint-config-typescript`, put it in the same place:
```ts
// eslint.config.ts
import { defineConfigWithVueTs, vueTsConfigs } from "@vue/eslint-config-typescript";
import pluginVue from "eslint-plugin-vue";
import pluginVueZamn from "eslint-plugin-vue-zamn";
import skipFormatting from "eslint-config-prettier/flat";
export default defineConfigWithVueTs(
{ files: ["**/*.{vue,ts,mts,tsx}"] },
...pluginVue.configs["flat/recommended"],
vueTsConfigs.recommended,
...pluginVueZamn.configs.recommended,
skipFormatting,
);
```
## `configs.recommended`
For `*.vue` files, it:
* sets vue-eslint-parser's `templateTokenizer` for `zamn`, given as a path, so it is found wherever it is installed and `eslint --cache` can serialize the config;
* turns on `vue-zamn/no-parsing-error` as an error, and `vue-zamn/no-misleading-indentation` and `vue-zamn/prefer-shorthand` as warnings;
* turns off the rules of eslint-plugin-vue that are about how HTML is written:
| Rule | Why |
|---|---|
| `vue/component-name-in-template-casing` | its fix writes ``, and zamn has no self-closing form |
| `vue/html-indent` | indents as in HTML; the layout is [Prettier](./prettier)'s, and `vue-zamn/no-misleading-indentation` catches the indentation that matters |
| `vue/multiline-html-element-content-newline`, `vue/singleline-html-element-content-newline`, `vue/padding-line-between-tags` | their fixes break lines, and a line break ends a statement in zamn |
| `vue/html-quotes` | a bare value (`n=1`) is not a string to put in quotes; quotes are Prettier's job (`singleQuote`) |
| `vue/max-attributes-per-line`, `vue/first-attribute-linebreak` | decided by Prettier |
| `vue/html-end-tags`, `vue/html-closing-bracket-newline`, `vue/html-closing-bracket-spacing` | about `>`, `/>` and end tags, which zamn doesn't have |
Every other rule of eslint-plugin-vue works as it does on an HTML template, fixes included: `v-for` without `:key`, unused variables, `v-if` with `v-for` and the rest.
ESLint can't tell templates apart by language, so these rules are off for every `.vue` file the config applies to, HTML templates included. In a project that has both, narrow `files`:
```js
...vueZamn.configs.recommended.map((config) => ({ ...config, files: ["src/zamn/**/*.vue"] })),
```
## Rules
### `vue-zamn/no-parsing-error`
Reports zamn's syntax errors, each over the source it is about, with its hint:
```text
div {
a(href=base + "/docs") Docs
^^^^^^^^^^^^^^ JavaScript expressions are not supported in attribute
values: zamn has no JavaScript; quote the value, or
write a binding such as `:href` for your framework.
}
```
It has no options, and says nothing about HTML templates. Keep `vue/no-parsing-error` on as well: that rule reports syntax errors in expressions (`:title="1 +"`), zamn templates included, and leaves zamn's own errors to this one.
### `vue-zamn/no-misleading-indentation`
Reports a line indented as if it were a child, without braces. Indentation means nothing in zamn, so such a line is a sibling, and zamn warns about it ([`MISLEADING_INDENTATION`](../guide/syntax/brace-blocks#indentation)):
```zamn warning=MISLEADING_INDENTATION
p Some text
b bold
```
```text
p Some text
b bold
^^^^^^ This line is indented as if it were nested, but indentation means
nothing in zamn: wrap the children in `{ }` on the line above, or
remove the indentation.
```
The template still compiles, which is why the config turns it on as a warning. It has no options. [Prettier](./prettier) re-indents the template, which fixes it in one of the two ways: if the line was meant to be a child, put it in `{ }` first.
### `vue-zamn/prefer-shorthand`
Reports a `class` or `id` attribute with a static value, and fixes it to the shorthand. Classes keep their order, and a `div` tag goes, since an element without a tag is a div:
```text
p(class="a b" title="t") → p.a.b(title="t")
div(id="app" class="page") → #app.page
```
Bindings (`:class`), values a shorthand cannot hold (`id="a b"`, `class="a&b"`) and a second id are left alone. The config turns it on as a warning. The `attributes` option picks what it checks, both by default:
```js
"vue-zamn/prefer-shorthand": ["warn", { attributes: ["class"] }],
```
### `vue-zamn/component-name-in-template-casing`
[`vue/component-name-in-template-casing`](https://eslint.vuejs.org/rules/component-name-in-template-casing.html) with a fix that works in zamn. It takes the same options and is Vue's rule itself: which names are components, which are checked and what the right name is are all decided there. In a zamn template only the fix differs, renaming the tag and nothing else:
```text
MyCard.big(title="a") → my-card.big(title="a")
```
In an HTML template it behaves exactly as Vue's rule, so it can replace it in a project that has both kinds.
## Comments
All four kinds of [comments](../guide/syntax/comments) are comments to ESLint, so directives work in any of them. `//` is the one to use, since it stays out of the HTML:
```zamn
// eslint-disable-next-line vue/no-v-html
article(v-html="post.body")
/* eslint-disable vue/no-v-html */
section(v-html="post.intro")
/* eslint-enable vue/no-v-html */
```
## What rules see
The same template AST an HTML template gives, positioned on the zamn source:
| zamn | AST |
|---|---|
| `tag`, `.class`, `#id`, `(...)` | the start tag of a `VElement` |
| `name="value"` in `(...)` | `VAttribute`, or a directive with its expression parsed |
| `name=true` | an attribute without a value |
| `name=false` | nothing, as in the output |
| text, `\|` lines, `\|{ }` blocks | `VText`, with the text as the browser shows it: escapes such as `\{` resolved, character references such as `→` decoded, and the indentation `\|{ }` strips left out |
| `{{ expr }}` in text, `tag= expr` | `VExpressionContainer` |
| `script` and `style` content | `VText`, as written |
| `//`, `//!`, `/* */` and `/*! */` | comments |
| the `}` of the element's block, of its `tag: \|{ }` text or of the `#{ }` it is in, its `/script` line, or else the end of its statement: its line break, or the `}` of the block it is in | the end tag |
Elements that end at the same `}`, as in `ul { li: a Home }`, share it as their end tag. Variables of `