--- 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

Hello

Written in zamn .

``` 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 `