Writing
Single-page view · as markdown
Writing Articles and Frontmatter
Trail / Writing
An article is a single .md file named <order>--<slug>.md: a YAML
frontmatter block, then markdown.
- -
The frontmatter is required and must be the first thing in the file: a line of
exactly ---, the YAML, and a closing ---. A file that does not start with
---, or whose block is never closed, is a build error. So is any key not
listed below — a typo'd descripton: fails the build rather than silently
doing nothing.
Complete the task #
-
Choose a topic or book in an existing site for the article.
-
Create a Markdown file using the order and slug conventions in
trail-source(5). -
Add the title and description frontmatter. In a topic, also choose the page type; omit that field in a book.
-
Write the article body after the closing frontmatter delimiter.
-
Run
trail build --strictfrom the site root and check the rendered title, description, and related links.
The keys #
The field and rule reference is in trail-frontmatter(5).
The title field #
The only key every article must have, in topics and books alike. It is not derived from the slug — unlike a topic or chapter title, an article states its own.
The type field #
Required on every article in a topic, and rejected on every article in a book.
Trail does not constrain the value or display it on the page; it is carried
through to site.json for tooling that wants to filter by it. What it is
really for is the author: deciding whether a page is a concept (explaining
how something works), a how-to (walking through a task) or a reference
(exhaustive, looked-up rather than read) is a genuinely useful discipline, and
pages that cannot answer the question are usually two pages.
Inside a book the question is already answered — a specification is read in order — so trail rejects the key rather than let it sit there meaning nothing.
The description field #
Optional, but write one. It becomes:
- The page's
<meta name="description">andog:description, which is what search engines and chat apps show; - The standfirst line in the page's markdown mirror;
- The
descriptionfield insite.json.
It is not displayed on the page itself, and it is not the in-site search snippet — Pagefind builds those from the body text around the match.
Build with --strict to make a missing description a
build failure. Alias pages are exempt, since the original carries it.
The related field #
A list of page references, in the same grammar body links use but without
the leading ~:
related:
- pekit/running/invocation
- peios/package-management/overview
They render as a "Related Content" list under the article, and they appear in
the page's markdown mirror and in site.json. Resolution is as strict as a
body link: an ambiguous reference always fails the build, and a missing one
fails unless --allow-dangling-links is set, in which case it warns and drops
from the list.
inline_ref #
Phrases that should become links to this article wherever they appear in the site's prose:
inline_ref:
- PCDS GUID
- PCDS GUIDs
Every occurrence in ordinary prose, anywhere on the site, links here — except on this page itself. Phrases are claimed site-wide and exclusively; two pages claiming the same phrase is a build error. See Inline references.
The updated field #
An ISO date, and validated as one — 2026-05-01, not May 2026 and not
01/05/2026.
updated:
It shows in the page's meta line, and it becomes the page's <lastmod> in
sitemap.xml. It is deliberately manual: file modification times are noise (a
whitespace fix is not an update, and a checkout rewrites them all), and trail
does not read git history. An article with no updated: does not show one.
reading_minutes #
Trail estimates reading time from the body's word count at 200 words a minute, rounded up, with a floor of one minute. Code blocks count — they are read, differently.
Set reading_minutes: when the estimate is wrong: a dense reference table
reads far slower than its word count suggests, and a page that is mostly a
long code listing far faster.
reading_minutes: 30
Roll-ups #
Reading times and dates add up the tree. A subfolder totals its articles; a topic totals its articles and subfolders; a book totals its chapters; an anthology totals its topics and books; a product totals everything in it.
- Reading time is the sum, so a book's cover can say how long the whole book takes and a topic card can say how long the topic is.
updatedis the most recent date anywhere beneath, so a container reflects its freshest page.
Roll-ups are computed after .link aliases are resolved, so an aliased
article counts in the totals of the place it was linked into.
The body #
Everything after the closing --- is CommonMark
with GitHub extensions: tables, strikethrough, footnotes, and
> [!NOTE]-style admonitions.
On top of that, trail adds:
~pagereferences — link by page identity instead of URL.- Co-located images —
beside the article, with dimensions filled in and captions turned into figures. - Syntax-highlighted code blocks with copy buttons.
- Tab groups and mermaid diagrams.
- Inline references,
§section citations, and RFC-2119 keyword highlighting.
A few things happen to headings automatically: h2 and h3 become the "On
this page" list, every heading gets a stable id and a permalink anchor, and
inside a book they carry their section numbers as real text. Ids come from the
heading text, with a numeric suffix if two headings on a page would otherwise
collide.
Tables are wrapped in their own horizontally-scrolling container, so a wide table never makes the whole page scroll sideways.
Naming and ordering #
The filename is not decoration:
200--quick-start.md
│ └── the URL segment, and what you write in a ~link
└── the sort key among siblings — never shown, never in a URL
Two files sharing an order in the same directory is an error. Numbering in hundreds leaves room to insert later; inside a book the prefix is the published section number, so number from 1 there instead.
print is a reserved slug — every container publishes a /print page — so
100--print.md is rejected.
Writing Links and References
Trail / Writing
Trail links pages by identity, not by URL. Instead of writing a path that
breaks the moment a page moves, you write a ~ reference naming the product
and enough of the page's slugs to be unambiguous:
Reorganize the tree — move that topic into an anthology, wrap it in a shelf, renumber it — and the link still resolves. Delete the target, and the build fails and tells you every page that pointed at it.
Complete the task #
-
Find the destination page in the source tree and identify its product, grouping, and slug.
-
Write a descriptive link label and a qualified
~reference using the examples below. -
Add a fragment only when linking to a specific heading or explicit anchor.
-
Run
trail build --strictfrom the site root. Resolve reported missing or ambiguous targets, then check the destination in the built site.
The grammar #
~<product-slug>[/<segment>]…[#<fragment>]
- The first segment is always a product slug. There is no relative form and no site-wide search; every reference says which product it means.
- The remaining segments match the end of a page's path. Trail compares them against each page's slugs — the anthology slugs, the topic slug, any subfolder or chapter slugs, and the page's own — and matches if your segments are the tail of that list.
- Exactly one page must match. Zero or several is an error.
- A fragment can follow, and is appended to the resolved URL:
~pekit/reference/cli#global-flags. It is checked too: the target article must define that anchor — a heading id, a[*name]citation anchor, or an id written in raw HTML — or the link is broken. Fragments on product and anthology pages, which have no body, are not checked.
The rule of thumb is: write the shortest thing that is unambiguous, and add segments from the left only when you have to.
A worked example #
Given this page:
/peios/security-fundamentals/identity/tokens/issuing
└ anthology ───────┘ └ topic ┘ └folder┘ └page┘
all of these resolve to it:
~peios/issuing
~peios/tokens/issuing
~peios/identity/tokens/issuing
~peios/security-fundamentals/identity/tokens/issuing
~peios/issuing is the one to write — until a second page in peios is also
called issuing, at which point that reference becomes ambiguous, the build
fails, and you add a segment.
Note that the deeper segments are for disambiguation only. A chapter or subfolder slug can appear in a reference even though it is not a page you could link to on its own.
What can be a target #
| Item | Targetable | Reference |
|---|---|---|
| A product | yes | ~pekit |
| An anthology | yes | ~peios/security-fundamentals |
| A book cover | yes | ~peios/pgss |
| An article | yes | ~pekit/reference/cli |
| A topic | no | link to an article in it |
| A topic subfolder | no | (except as a .link target) |
| A book chapter | no | link to an article in it |
| A shelf | no | it has no page at all |
Topics, subfolders and chapters have no page of their own, so there is nothing for a reference to land on. Link to the article you actually mean.
Ordinary links still work #
A ~ at the start of a destination is what makes it a reference. Everything
else is left alone:
Root-relative links are the escape hatch for the handful of URLs that are not
pages — /print views, /llms.txt, /site.json. They are not checked, so
they are also the way to ship a broken link. Prefer ~ wherever the target is
a page.
A same-page fragment is checked, against the page's own heading ids,
citation anchors and raw-HTML ids. Heading ids are derived from the heading
text — lowercased, every run of non-alphanumerics collapsed to one hyphen, so
## vm:run(cmd, opts) is #vm-run-cmd-opts — and a repeated heading gets
-2, -3, … appended. Inside a /print bundle the link is namespaced along
with the ids it points at, so it keeps working there.
One form is always an error: a relative path, such as
../410--network-policy.md. Pages are addressed by their slugs, not their
source files, so no relative path can ever reach one; the build rejects it and
tells you to write a ~ reference instead.
~ is only meaningful in a link destination. In an
image destination it is an error, with a message
saying so: images are files, addressed relative to the article.
Where else references are used #
The same grammar appears in three other places:
# an article's frontmatter — no leading ~
related:
- pekit/running/invocation
# a .link alias file — with the ~
= "~pekit/running/signing-and-provenance"
# the root trail.toml's nav — with the ~, or an external URL
[[]]
= "Specs"
= "~specifications/pgss"
The related: list is the odd one out in dropping the ~; everything else
keeps it.
When a link breaks #
Every link in the site is checked on every build, and all the failures are reported together — one build tells you the whole story rather than stopping at the first bad reference.
Error: 3 broken links:
in article '/pekit/recipes/anatomy': link '~pekit/running/invokation' matches no page in product 'pekit'
in article '/peios/identity/sids': link '~pekti/overview' names unknown product 'pekti'
in article '/pekit/reference/cli': link '~pekit/targets' is ambiguous; candidates:
~pekit/running/commands-and-targets/targets
~pekit/reference/recipe-format/targets
There are five failure kinds, and they are not treated alike:
| Item | Means | With --allow-dangling-links |
|---|---|---|
| Unknown product | the first segment is not a product slug | warning |
| No match | nothing in that product ends with those segments | warning |
| Missing anchor | the page exists but defines no such #fragment — on a ~ reference or a same-page link | warning |
| Relative path | the destination is a file path, which no page can serve | warning |
| Ambiguous | two or more pages match | still fatal |
Ambiguity is never downgradable. A missing target is a link that does nothing; an ambiguous one is a link that goes somewhere specific and possibly wrong, and only the author knows which page was meant.
--allow-dangling-links is for the middle of a refactor, when you have moved
a hundred pages and want to see the site before fixing every reference. It is
not a setting to leave on.
References in print views and mirrors #
The single-page and markdown views rewrite references so they still work away from the site:
- In a
/printbundle, a reference to a page inside the same bundle becomes an in-document anchor, so the whole document navigates itself. A reference to a page outside it becomes an absolute URL when the site config has aurl, and stays root-relative otherwise. - In a
.mdmirror, a reference becomes the target's own.mdURL, so a reader following links through the markdown surface stays in it.
Adding Images
Trail / Writing
Images live beside the articles that use them. There is no assets
directory to maintain and no separate URL scheme to remember: drop the file in
the same folder as the .md, and reference it by name.
2--logon.topic/
├── 100--overview.md
└── logon-flow.svg
The image publishes at the URL of the directory it was found in, keeping its
own file name — here /peios/logon/logon-flow.svg. Move the folder and the
image moves with it.
Complete the task #
-
Place the image beside an article, using a supported extension and a lowercase slug filename.
-
Add Markdown image syntax with meaningful alternative text and a path relative to the article.
-
Add the variants or sizing syntax described below when needed.
-
Run
trail build --strictfrom the site root and check the image in the built page.
Referencing #
Destinations resolve relative to the article's own .md file, exactly as
an editor's markdown preview resolves them. Relative paths can climb out of a
subfolder with .., so a diagram shared by a folder's worth of articles can
sit one level up:
2--concepts.topic/
├── shared-diagram.svg
└── 300--replication/
├── 100--topology.md 
└── 200--conflicts.md 
Three kinds of destination are left exactly as written and never checked:
absolute URLs (https://…), root-relative paths (/…) and data: URIs.
A ~ reference in an image destination is a build error. ~ names pages, not
files.
Where images can sit #
Anywhere articles can sit: a topic, a topic subfolder, a book, or a book
chapter. Not in a product, anthology, or shelf directory — those hold only
trail.toml and subdirectories.
The file name must be a valid slug plus a lowercase extension:
logon-flow.svg, not Logon Flow.SVG. Recognized extensions are:
png jpg jpeg gif svg webp avif
Anything else in an article directory is an "unexpected file" error — which is
the point. A .pdf or a .xlsx sitting in a content folder is almost always
a mistake, and trail would rather say so than quietly ignore it.
Dimensions #
Trail reads each raster image's header at build time and emits real width
and height attributes:
The browser can then reserve the right space before the file arrives, so text does not jump around as images load. SVGs get no dimensions — they scale — and neither does any file whose header cannot be read.
Captions and figures #
An image with a title — the quoted string after the destination — that
sits alone in its own paragraph becomes a <figure> with a <figcaption>:
How a logon token reaches the session service
The two strings do different jobs and should say different things. The alt text describes the image for someone who cannot see it. The caption is prose everyone reads, and can say what the diagram is for.
An image without a title, or one sharing its paragraph with other text,
renders as an ordinary inline <img>.
Unreferenced images #
Only images some article actually references are copied into the output. One that nothing references prints a warning and is left out:
warning: image '/…/2--logon.topic/old-diagram.png' is not referenced by any article and was not published
A warning rather than an error, deliberately: adding the file before the article that will use it is a normal way to work. But a warning that stays warning is a file to delete.
A referenced image that does not exist is the other way round — a broken link,
fatal unless --allow-dangling-links downgrades it:
in article '/peios/logon/overview': image 'logon-flow.svg' not found (resolved relative to the article's folder)
In the other views #
Images work in the
markdown mirrors and /print bundles
too: since those serve an article's body away from its own folder, relative
destinations are rewritten to the image's published URL.
Diagrams #
For flowcharts, sequence diagrams and the like, consider a mermaid code block instead of an image file. Mermaid diagrams are text — diffable, editable, and they follow the reader's light or dark theme, which a checked-in PNG cannot.
Attachments
Trail / Writing
Declare downloads in the site root's trail.toml. Trail can copy a file or
package a directory as a .tar.gz archive. It validates the source and
references, publishes the download, and records its size and SHA-256 digest.
Declare a source bundle #
Keep the source in a dedicated directory outside the product tree:
docs/
├── trail.toml
├── download-sources/
│ └── tools/
│ ├── README.md
│ └── scripts/
└── example.product/
Add a declaration to the root configuration:
[[]]
= "example-tools"
= "Example Tools"
= "Configuration files and setup scripts."
= "download-sources/tools"
= "example-tools.tar.gz"
= "tar.gz"
= [".venv", "node_modules", ".cache", "results"]
source is relative to the declaring tree's root. The declaration makes its
top-level source directory legal there without publishing the loose files.
Each merged tree can declare its own attachments. IDs must be unique across
all trees.
exclude lists exact paths relative to the bundle directory. A directory
entry excludes its whole subtree; entries are not glob patterns. All other
files, including hidden files, enter the archive. Keep generated environments
and local output outside the bundle or list them explicitly.
Declared attachment sources are data, so trail lint does not treat their
Markdown files as documentation articles. Check bundled code and README files
with the bundle's own tools.
Trail rejects symbolic links, special files, paths outside the source tree, and sources that overlap the build output. It never executes bundled code.
Publish a single file #
Use format = "file", the default, for a PDF, configuration file, or archive
produced by another tool:
[[]]
= "example-config"
= "Example Configuration"
= "A starting configuration for the example service."
= "download-sources/example.toml"
= "example.toml"
The published bytes match the source. File attachments do not accept exclusions.
Link to downloads and metadata #
Use the exact ID in an attachment reference:
The first reference resolves to
/attachments/example-tools/example-tools.tar.gz. The second resolves to
/attachments/example-tools/metadata.json. Missing references are link
errors; --allow-dangling-links can downgrade them like other unresolved
references. Valid attachment links produce no --strict advisory warning.
Attachment links retain file URLs in Markdown exports. Print links use the configured site URL, and cache-busting copies keep their own download URLs.
The attachments product slug and passthrough output directory are reserved
when a site declares attachments. IDs and filenames start with an ASCII
letter or digit and contain only ASCII letters, digits, dots, underscores,
and hyphens. The ID index.json and filename metadata.json are reserved.
Inspect download metadata #
Each metadata file contains schema_version (1), id, title,
description, filename, url, metadata_url, format, media_type,
size_bytes, and sha256. The digest covers the published bytes, including
compression for archives. /attachments/index.json lists the same records
in ID order. These records omit local source paths.
Generated archives use application/gzip; copied files use
application/octet-stream in the metadata. The hosting server controls its
HTTP content type and download headers. Trail does not configure that server.
Rebuild bundles #
Archive entries are sorted and placed under one directory named after the
attachment ID. Trail preserves file contents and whether Unix files are
executable; other permission bits, ownership, and timestamps are normalized.
Directories and executable files use mode 0755; other files use 0644.
Empty directories are preserved. Identical inputs with the same Trail build
produce identical archives, independent of checkout location or file dates.
Content and executable-mode changes invalidate the archive cache. Unchanged
downloads retain their output modification times. Removed declarations prune
their downloads and metadata on the next successful build. trail serve
also detects changes to declared hidden inputs and executable modes.
Writing Code Blocks
Trail / Writing
Fenced code blocks work as they do in any markdown, with an info string naming the language:
Trail highlights that at build time and wraps it with a copy button:
…
fn …
Complete the task #
-
Choose a language name for the block, or
textfor unhighlighted output. -
Write a fenced code block in an article using that language name.
-
Put commands in a shell block without a prompt, and show their output in a separate
textblock. -
Run
trail build --strictfrom the site root and check the highlighting and copy button.
Highlighting is classes, not colors #
Highlighting happens once, when the site is built — there is no highlighter shipped to the browser and no flash of unstyled code.
What is emitted is class names, not inline colors: hl-keyword,
hl-string, hl-comment and so on, prefixed so they cannot collide with the
theme's own classes. Those classes resolve through the same CSS custom
properties as everything else on the page, which is why code follows the
reader's light or dark choice instead of freezing one palette into the markup.
Theming covers the tokens involved.
The copy button #
Every code block gets one. It sits in the top-right corner, appears on hover (and is always visible on touch devices), copies the block's text to the clipboard, and briefly says so.
Nothing is stripped from what it copies, so a $ prompt in a shell example is
copied along with the command. Write shell examples without prompts if you
would rather they paste cleanly.
Code blocks returned by plugins preserve whitespace-only lines, including spaces, tabs and form feeds. This also applies inside lists and blockquotes, so live file excerpts retain their content when Trail inserts the plugin output.
Which languages are highlighted #
Trail bundles syntect as its
highlighter, with the extended syntax collection from
two-face — the same
definitions bat ships, a little over two
hundred of them. The info string is matched against a syntax's name or one of
its file extensions, case-insensitively, so both rust and rs work.
Everything you are likely to reach for is covered:
bash / sh / fish / zsh asm awk cmd / bat c / c++ / c#
clojure cmake coffeescript crystal css / scss / sass / less / stylus
d dart diff dockerfile dotenv elixir elm
erlang f# f90 gd gitconfig / gitignore
glsl go / gomod graphql dot groovy haskell hcl / terraform
html http idris ini java js jq
json / jsonnet julia kotlin latex / bibtex lean
lisp llvm lua make markdown matlab nginx
nim nix objective-c ocaml odin orgmode pascal
perl php protobuf puppet purescript python qml
r racket rego robot ruby / haml / slim rust
scala solidity sql svelte swift systemverilog / verilog / vhdl
tcl toml typescript / tsx typst vim vue
wgsl xml / svg yaml zig
…alongside the config and system formats that turn up in documentation:
crontab, fstab, passwd, resolv, syslog, ssh_config, known_hosts,
.htaccess, requirements.txt, csv / tsv, manpage, strace, email.
Still absent: powershell, and the shell-session forms (console,
shell-session). A console block renders as plain text — which is usually
what you want anyway, since a $ prompt is not shell syntax.
An info string the set does not recognize is not an error and does not
fail the build: the block renders as plain escaped code, with the same
wrapper, the same copy button, and its language still recorded on it as
data-language.
The exception is an info string that opens with {name}. That is a
plugin block, expanded by a command the site
configures, and naming a plugin that is not configured is an error.
Two languages are not code at all: mermaid blocks become
diagrams, and math blocks
become equations.
The definitions' licenses ship with every build at
/assets/LICENSE-Syntaxes.txt.
Blocks with no language #
A fence with no info string renders as escaped plain text, with the wrapper and copy button intact. Use one for output, trees, and anything that is not a language:
Across this site the convention is text for that. The highlighter does not
recognize text as a language, so it renders identically to a bare fence
while reading more explicitly in the source.
Indented code blocks (four spaces) are supported too, and are treated as having no language.
Inline code #
Inline `code` is ordinary markdown and is not highlighted. It is also
excluded from inline reference matching: a
claimed phrase inside backticks stays plain text, so writing `PCDS GUID`
when you mean the literal string does not produce a link.
In the other views #
Code blocks survive into the
markdown mirrors and /print bundles as
ordinary fenced blocks with their info strings intact — the mirrors reproduce
your source, not the rendered HTML. Plugin blocks are the exception: they
appear expanded.
Writing Equations
Trail / Writing
Equations are written in TeX, in one of two forms, both of which GitHub renders the same way.
An equation on its own goes in a code block tagged math:
which renders as:
An equation inside a sentence is a code span with a dollar sign hard against each side:
which renders as: the average decays by a factor of each sample.
Each math block holds one equation. Several lines are one equation only
inside an environment that sets them out, such as align* with its & and
\\:
Complete the task #
-
Choose an inline expression or a display equation using the syntax below.
-
Write the expression in an article, keeping its delimiters balanced.
-
Run
trail build --strictfrom the site root and resolve any equation errors. -
Check that the rendered equation is legible at the page reading size.
Plain dollar signs are text #
$x$ is not an equation. Documentation is full of dollar signs that are
nothing of the kind: $PATH and $HOME, costs $5 or $10,
$dport_dev ($dport_dev. Any two of those in a paragraph would pair up into a
garbled equation, and no error would say so. The code-span form never happens
by accident, and a dollar sign needs no escaping anywhere.
What sits inside a math block or the code span is passed to TeX exactly as
written. Markdown escapes don't apply there, so \_ stays \_.
What it becomes #
Trail renders each equation to MathML, which browsers lay out natively, at build time:
- No script and no font download. An equation works in print bundles and with JavaScript off.
- The TeX stays with the equation. It is attached as an annotation, so screen readers and copying can use it.
- The Markdown mirrors keep the TeX as written. Readers of the mirror get the fence or code span, which they can render themselves.
An equation on its own is spaced like a paragraph. If it is wider than the column, it scrolls rather than squeezing.
TeX that doesn't parse #
An equation that fails to parse fails the build, as a broken link does, naming the equation and what is wrong with it:
in article '/guide/colour': equation '\frac{1}' is not valid TeX: parsing error: expected a token
Trail renders with
pulldown-latex, which covers
the commands of everyday mathematics: fractions, roots, sub- and superscripts,
\text, \left/\right, Greek letters and relations, and the align,
matrix and cases families of environments.
Adding Admonitions, Tabs, and Diagrams
Trail / Writing
Three constructs on top of ordinary markdown handle the things prose alone does badly: setting something apart, showing the same instruction several ways, and drawing.
Complete the task #
-
Choose the element that fits the content: an aside, alternative views, or a diagram.
-
Add the corresponding syntax from the sections below to an article.
-
Keep an admonition marker on its own blockquote line and close tab groups and fenced diagrams.
-
Run
trail build --strictfrom the site root and check the result in a browser.
Admonitions #
Admonitions use GitHub's alert syntax — a blockquote whose first line is a marker:
Five kinds exist, and no others:
| Marker | Renders as | For |
|---|---|---|
> [!NOTE] | Note | An aside worth knowing, not worth interrupting for. |
> [!TIP] | Tip | A shortcut or a better way. |
> [!IMPORTANT] | Important | Something a reader who skims will regret missing. |
> [!WARNING] | Warning | Something that will go wrong. |
> [!CAUTION] | Caution | Something that will go irreversibly wrong. |
The body is full markdown — lists, code blocks, links, all of it.
A blockquote whose first line looks like a marker but is not one of the five is a build error, not silently-rendered text:
unknown admonition type '[!WARN]' (expected NOTE, TIP, IMPORTANT, WARNING or CAUTION)
That is deliberate. A typo'd marker renders as a quotation with [!WARN]
sitting at the top of it, which nobody proofreading their own page ever
notices.
An ordinary blockquote — no marker — is still an ordinary blockquote.
Tab groups #
Tab groups show the same instruction several ways, so a page does not have to repeat itself per platform, per shell, or per package manager.
The grammar is three markers, each alone on its own line:
| Marker | Meaning |
|---|---|
:::tabs | Opens a group. |
:::tab <label> | Starts a tab. The label is everything after the marker. |
::: | Closes the group. |
The first tab is shown; the rest are hidden until selected. Each panel's body is full markdown, so a tab can hold code blocks, lists, admonitions and images.
Rules, all of them enforced at build time:
- A group must be closed — an unclosed
:::tabsis an error. - A group must contain at least one
:::tab, and each:::tabneeds a label. - Nothing but blank lines can appear between
:::tabsand its first:::tab. - Groups cannot nest.
:::taboutside a group, or:::with no group open, is an error.
Markers inside fenced code blocks are left alone, which is how this page can show the syntax without triggering it.
Diagrams #
A code block tagged mermaid is rendered as a diagram in the browser:
Any mermaid diagram type works — flowcharts, sequence diagrams, state diagrams, ER diagrams, Gantt charts, and the rest.
The mermaid library is a large script, so it is only shipped to pages that actually contain a diagram. A site with no diagrams anywhere never emits it at all.
The diagram is drawn in the reader's current theme, light or dark, chosen when the page loads. Switching theme afterward re-styles the rest of the page but leaves already-drawn diagrams as they were until the page is reloaded.
Diagram or image #
Prefer mermaid when the diagram is boxes, arrows and labels. It is plain text in your source: diffable, reviewable, editable by whoever is next in the file, and it follows the reader's theme.
Reach for an image when the thing is genuinely pictorial — a screenshot, a photograph, an illustration, or a diagram whose layout matters more than mermaid will let you control.
Inline References
Trail / Writing
Some terms should always be links. If there is one page explaining what a PCDS GUID is, then every "PCDS GUID" written anywhere on the site ought to point at it — and nobody wants to write that link by hand a hundred times, or notice the ninety-nine places it was forgotten.
An inline reference is a phrase a page claims. Trail then links every occurrence of that phrase in the site's prose to the claiming page, automatically.
Declaring a phrase #
Declaration is self-service: a thing declares the phrases that mean it, in its own file. There is no central glossary to maintain.
An article declares in its frontmatter:
---
title: Globally unique identifiers
type: reference
inline_ref:
- PCDS GUID
- PCDS GUIDs
---
Everything else declares in its trail.toml:
# 2--pgss.book/trail.toml
= "Peios Generic System Standards"
= "PGSS"
= "Cross-platform system standards from the Peios Project"
= ["PGSS", "Peios Generic System Standards"]
Phrases are matched literally, so plurals and alternative spellings are separate claims. List them all.
Where a phrase lands #
| Declared on | Links to |
|---|---|
| An article | that article |
| A product | the product's landing page |
| An anthology | the anthology's landing page |
| A book | the book's cover — and § can reach a section |
| A topic | the topic's first article |
| A topic subfolder | the folder's first article |
| A book chapter | the chapter's first article |
The pattern is: the declarer's own page, or — for the containers that have no page — the first article inside it. A container that declares a phrase but holds no articles to land on is a build error.
A shelf can not declare a phrase at all, since it has neither a page nor articles of its own. Declare it on the shelf's items.
Where phrases are matched #
In ordinary prose, and only there. Matching skips:
- Headings, whose ids are derived from their text;
- Link text — a phrase inside an existing link is left alone, so a deliberate link is never rewritten;
- Image alt text;
- Code blocks and inline code — writing
`PCDS GUID`when you mean the literal string produces no link; - The claiming page itself, which never links to itself.
Two more rules make matching predictable:
- Whole words only. A phrase surrounded by letters, digits, or underscores does not match. "PCDS GUIDs" does not match inside "PCDS GUIDsomething".
- Longest wins. When two claimed phrases overlap at the same position, the longer one is used — so "PCDS GUID" beats "PCDS", and a phrase does not get chopped up by a shorter one inside it.
Phrases are exclusive #
A phrase belongs to exactly one declarer, site-wide. Two things claiming the same phrase is a build error:
inline_ref phrase 'PCDS' is claimed by both book '/peios/pcds' and article '/peios/formats/pcds-overview'
That is the whole point: if two pages both want to own a term, the ambiguity is real and a reader would have been sent to the wrong one. Decide which page is the destination.
Empty phrases, phrases with leading or trailing whitespace, and phrases
containing § are also errors.
Link aliases never claim phrases —
the original keeps them.
Choosing phrases well #
Inline references are powerful in the way find-and-replace is powerful. A phrase that is too common turns the site into a sea of blue.
- Claim terms of art, not ordinary words. "PCDS GUID" is a term. "identity" is a word.
- Claim what a reader would want defined. The test is whether someone meeting the phrase mid-sentence would benefit from a link.
- Prefer the specific form. Claiming "GUID" catches every passing mention; claiming "PCDS GUID" catches the ones that mean your page.
- Remember plurals and expansions — they are separate claims, and a term claimed in only one of its forms links inconsistently, which reads worse than not linking at all.
Section citations with § #
A phrase claimed by a book can be extended with a section number in prose:
"PGSS §2.1" becomes one link to that exact section. The suffix is a single
space (or non-breaking space), the § sign, and a section label — digits,
dots, and appendix letters: §2, §2.1.3, §A, §B.2. A sentence-ending
full stop is not part of the label.
Every book carries an index of its section numbers, covering:
- articles, by their section number (
§2.1→ that article's page); - chapters, by theirs (
§2→ the chapter's first article); - headings inside articles — the
h2andh3numbers trail generates (§2.1.3→ that article, at that heading).
So a citation can be as precise as a subsection of a page.
A § label that does not resolve is a build error — with the phrase still
linked to the book, so the page is not broken while you fix it:
'PGSS §9.9' does not match any section of '/peios/pgss'
Like a broken ~link, it is downgraded to a warning by
--allow-dangling-links.
Bare § inside a book #
Within a book's own pages, a bare § reference resolves against the
surrounding book, with no phrase needed:
Unlike the phrase-qualified form, a bare § that does not resolve stays
plain text and says nothing. That is not an oversight: specifications
routinely cite sections of other documents, and a build that failed on every
"§9.9 of RFC 3986" would be unusable. The qualified form names its book and so
can insist; the bare form cannot, so it does not.
RFC-2119 keywords #
Requirement keywords are highlighted everywhere on the site, with no configuration and nothing to declare:
MUST · MUST NOT · REQUIRED · SHALL · SHALL NOT · SHOULD · SHOULD NOT · RECOMMENDED · NOT RECOMMENDED · MAY · OPTIONAL
They must be written in capitals, as RFC 2119 intends — the capitals are what distinguishes a requirement from the ordinary English word. Matching is whole-word and longest-first, so "MUST NOT" highlights as one keyword rather than as "MUST" followed by a stray "NOT", and it skips the same places phrase matching skips: headings, links, and code.
The styling is a weight and the product's accent color, not a badge. It is meant to make a requirement scannable in a page of prose, and it works in ordinary articles as well as in books.
Named Citations
Trail / Writing
A § reference reaches an article. That is usually the right size for prose —
but not for a test. A test verifies one statement, and an article holds many;
"this test covers §4.6" cannot tell you which of §4.6's nine statements is
still unverified.
A named citation is an anchor on a single statement:
Anything outside the site can now point at exactly that sentence:
// Verifies PKM *copy-up.preserves-ownership
The build collects every anchor into citations.json, so a test suite can ask
which citations nothing yet verifies.
Anchors on headings #
An anchor on a heading names the whole section:
This is usually what you want. A well-structured document already gives a behavior its own section, so the section is the citable unit, and an anchor on a heading rides the structure rather than one sentence of prose that can later be rewritten.
The marker renders inside the heading and contributes nothing to the heading's id or its table-of-contents entry, so it is safe to add to an existing heading — nothing that linked to that section breaks.
In citations.json a heading anchor is reported with "kind": "section" and
its context is the heading text; everything else is "kind": "statement". A
coverage report wants the difference: an uncovered section is a
different-sized gap from an uncovered sentence.
Reach for a statement anchor when one section states several independent rules — a table of error conditions, or a numbered list — where one name for the section would be too coarse to say which rule is untested.
An anchor is a locator #
It marks a place, not a span. [*copy-up.preserves-ownership] says "the
statement here is called this"; it does not say where that statement begins or
ends, and Trail never tries to work that out.
That is deliberate. A name is arbitrary, so nobody argues about it and nobody revises it. An extent looks like it has a correct answer — does the following clarifying sentence belong inside? the exception clause? — so it invites disagreement and revision, and every revision is churn that helps none of the things a citation is for. Overlapping and nested statements have no clean bracketing rules either.
So an anchor is a pointer, and a reader follows it and reads.
One citation, many tests #
Coverage is "does this citation have at least one passing test". It is never a one-to-one mapping.
A statement in a specification is often close to one testable behavior. In a reference manual it usually is not: an anchor is as much a way of dividing a large descriptive document into consumable chunks as it is a single assertion. Getting closer to one-anchor-one-behavior is better where it happens naturally, but it is not a requirement, and a report that assumes it will mislead.
Writing anchors #
Put the anchor at the end of the statement it names. Do it as a separate pass, after the prose is written — annotating while drafting interrupts the writing, and picking out testable statements is a different kind of attention from composing them.
A name is lowercase alphanumerics in dot- or hyphen-separated segments, starting and ending alphanumeric:
| Item | Meaning |
|---|---|
copy-up.preserves-ownership | ✅ |
mount.strata.order | ✅ |
Copy-Up.Ownership | ❌ uppercase |
copy..up | ❌ doubled separator |
.leading | ❌ must start alphanumeric |
The grammar is enforced at build rather than merely recommended: a name is what every citation greps for, so a corpus with three naming styles is a corpus where a search misses things.
A name must be unique within its book, and the build fails if one is
declared twice. Uniqueness is per book rather than site-wide — unlike an
inline_ref phrase — because names are naturally book-scoped and a citation
from outside is qualified by the book's short name anyway.
Only a book can carry an anchor. A citation is addressed through its book, so an anchor in a task-doc topic could never be cited; the build rejects it rather than leaving it silently unreachable.
Retiring one #
Delete the anchor, and grep the name to find the tests and comments that pointed at it. Do not reuse a retired name for a different statement: nothing can detect that, and every existing citation silently comes to mean something else.
How it renders #
A small superscript marker, positioned out of the text's flow so line height and wrapping are exactly as they would be without it. Selecting copies the full citation string — the thing you want in a test — rather than navigating; the link still targets the anchor, so "copy link address" and middle-select behave normally, and the page works without JavaScript.
Readers who would rather not see them at all can call
trailToggleCitations(), which persists per browser.
What the build produces #
citations.json, at the site root, listing every anchor in the corpus:
It is its own file rather than part of site.json, which is a tree of the
whole site: the consumers here want a list they can read without walking one.
context is the source block the anchor sits in, not the statement it
marks — an anchor delimits nothing. Two anchors in one paragraph get the same
context. Treat it as a label for a coverage report, and follow url when you
need the real thing.
Anchors are also left as written in the markdown mirrors, so an agent reading
print.md sees them.
Anchors in code samples stay literal #
[*name] inside a fenced block or inline code is never an anchor, which is
what lets this page show the syntax. Everywhere else, an anchor is rewritten
before the markdown is parsed — otherwise the * could pair with an emphasis
marker elsewhere in the paragraph and swallow the anchor into an <em>.
Writing Plugin Blocks
Trail / Writing
Some content is not written but derived: API reference extracted from source comments, tables generated from a schema. A plugin block asks an external command to produce that content at build time, so the page and its source can never disagree.
The fence's info string is {name}, which is how
MyST spells a directive. Trail hands
the block to the command the site configures under that name, and puts the
markdown that comes back where the fence was.
Complete the task #
-
Install or build the plugin command and confirm its version-1 process interface against
trail-plugin(5). -
Configure its command under
[plugins.<name>]in the site root configuration. -
Add a fence naming the configured plugin to an article, using the plugin's documented argument and options.
-
Run
trail build --strictfrom the site root and check that the generated content replaces the fence. -
Change a declared plugin input and rebuild to confirm that its output updates.
Writing a block #
```{name} argument
:option: value
:flag:
body
```
{name}names a plugin configured in the roottrail.toml. A{name}that is not configured is a build error, the same as a mistyped admonition marker. Otherwise it would render as a code block, and nobody notices a code block that should have been a page of reference.- The argument is everything after
{name}on the opening line. What it means is up to the plugin. - Options are
:key: valuelines at the start of the block. A flag has no value. An indented line continues the previous option's value, and a trailing\on a piece is dropped, as in reStructuredText. Giving the same option twice is an error. - The body is whatever follows the options, after one optional blank line.
A plugin block works anywhere a fenced code block does: inside list items and blockquotes, with backticks or tildes, at any fence length. To show the syntax on a page, as this one does, wrap it in a longer fence: the inner fence is then content, not a block. Indented code blocks are never plugin blocks.
An unclosed plugin fence is an error, because it would otherwise take the rest of the page as its body.
Configuring a plugin #
Plugins are declared in the root trail.toml, one table each:
[]
= ["python3", "../tools/docs/trail-kernel-doc/trail-kernel-doc", "--srctree", ".."]
command is the program and its arguments, run directly, not through a shell.
Two more keys, anchors and after, let a plugin
link to the rest of the site. A program
containing a / is a path relative to the site root and must exist. A bare
name is looked up on PATH. The working directory is the site root.
A plugin configured in a
merged tree's trail.toml treats
that tree's root as the site root throughout: its program path, working
directory, root and file are all relative to the tree, exactly as when the
tree is built alone. Its blocks can still appear on any page of the site.
Markdown can only name a configured plugin; it can never say what to run.
Building a site runs only the commands its trail.toml lists.
Plugin names are lowercase letters, digits, -, and _. The
trail.toml reference has the table's details.
What a plugin receives and returns #
Trail runs each plugin at most once per build, passing every one of its blocks on the site in a single request. A plugin with no blocks is not run at all. A plugin that cross-references its own output can therefore see everything at once: a function name in one block can link to the page where another block documents that function.
The request arrives as JSON on stdin:
The complete process and field reference is in trail-plugin(5).
The plugin answers on stdout:
Every block id must be answered exactly once, each answer with exactly
one of markdown or error. depends_on lists the files the output was
derived from, relative to the root or absolute.
A plugin that scans a directory, rather than reading files it was told about,
should list the directory as well as the files it read. A directory in
depends_on stands for the set of files beneath it, so a file added there or
removed counts as a change. Edits to those files count only through the files'
own entries.
The plugin's stderr is captured and replayed after execution, including on cache hits. Use it for diagnostic messages.
Linking to the rest of the site #
A plugin sees only its own blocks. To link to something another page defines,
such as a function documented by hand, it can ask for the site's anchors with
anchors = true in its table. Its request then carries one more field: every
page's explicit anchors, keyed by reference.
Explicit anchors are the ids written in raw HTML, <a id="…">, and
citation anchors. Heading ids are left out: Trail derives them from the
heading's words, so they change when a heading is reworded and are no basis
for generated links.
The anchors come from the pages as written, before any plugin's output is
added, so what one plugin generates never depends on another having run. To
link to targets that another plugin generates, name it in after:
[]
= ["python3", "../tools/docs/trail-kernel-doc/trail-kernel-include", "--srctree", ".."]
= true
= ["kernel-doc"]
Trail then runs kernel-doc first and adds the anchors in its output to those
kernel-include receives. Each plugin runs after every plugin its after
names. Independent plugins can run together in bounded groups; their results
and diagnostics retain dependency order, then name order. See
Build Cache for worker limits. after without
anchors, a name that is not a configured plugin, and a cycle all fail the
build.
The anchors are part of what a plugin's cached output depends on, so a new anchor on any page reruns the plugins that receive anchors.
When something goes wrong #
All of these fail the build:
- A plugin exits non-zero;
- It prints something that is not a valid response;
- It misses or repeats a block;
- It answers a block with
error.
Block errors and malformed fences are collected across the whole site and reported together, each against its source line:
2 plugin blocks failed:
kernel.product/2--driver-api.topic/1--core.md:14: kernel-doc: drivers/base/nope.c does not exist
kernel.product/2--driver-api.topic/3--bus.md:40: '{kernldoc}' fence names no configured plugin (configured: kernel-doc)
Generated content is ordinary content #
Expansion happens when the site loads, before anything reads a page. The markdown a plugin returns then behaves exactly as if it had been typed:
- Its headings and raw HTML
ids are anchors that links can target, and its own~links are checked during every build; - It counts toward reading time, unless the page's frontmatter sets
reading_minutes; - It is indexed for search and appears in
/printbundles; .linkaliases of the page carry it too.
That includes the markdown mirrors: a mirror shows the expanded content, not the fence. Readers of the mirror, people and machines alike, get the documentation rather than an instruction to go and generate it.
Expanded output is not expanded again. A {name} fence inside a plugin's
output stays a plain code block.
To keep the output separate from the text around it, Trail sets it off with blank lines. Inside a blockquote or a list item, every output line gets the container's prefix.
Rebuilds and caching #
Trail keeps each plugin's last successful output. It reuses that output as long as all of these are unchanged:
- The plugin's blocks: arguments, options, bodies, and the pages they are on. A line-number change reruns a plugin that emitted diagnostics.
- Everything in its
depends_on. Files are compared by content, and directories by the names of the files beneath them, skipping names that start with a dot (such as editors' swap files). The resolved executable also counts, including a bare command found onPATH. - For a plugin with
anchors = true, the anchors it receives.
Under trail serve, a dependency outside
the site root is watched as well, so editing a source file the plugin reads
rebuilds the site. A change reruns the whole plugin, not the affected blocks,
because the plugin can cross-reference across all of them.
The cache persists between processes in .trail-cache/. Use --no-cache
when inputs such as network state or time affect a plugin. See
Build Cache for invalidation and worker limits.
Checking Style
Trail / Writing
trail lint reads a site's sources and reports each breach of its writing
rules, with the file, line, and column. Every rule is off until the site turns
it on, and every dictionary and word list is the site's own, so Trail holds no
house style of its own.
The lint is a separate command. A build never runs it, so a site that doesn't use it is unaffected.
Findings and totals go to stderr:
trail: guide.product/1--basics.topic/100--intro.md:12:41: "e.g.": use "for example" [spelling]
trail: warning: guide.product/1--basics.topic/100--intro.md:30:18: add a serial comma before the last item [serial-comma]
trail: 1 error, 1 warning
The exit status is 1 if any breach is an error, and 0 otherwise. The
command-line reference has the details.
Complete the task #
-
Choose the writing rules, dictionaries, and banned words for the site.
-
Add the
[lint]configuration shown below to its roottrail.toml. -
Run
trail lint <root>and read findings on stderr. -
Correct the sources or add a justified, narrowly scoped suppression.
-
Run the check again. An exit status of 0 means no findings classified as errors remain.
Turning rules on #
Rules are configured in a [lint] table in the root trail.toml, below every
plain key:
[]
= ["spelling", "em-dash", "heading-levels", "line-length"]
= 78
= ["Peios", "Registry Editor", "netd"]
[]
= ["spelling/en_US.dic", "spelling/project-words.txt"]
= ["spelling/banned-words.txt"]
The field and rule reference is in trail-lint(5).
A malformed [lint] table fails trail build too, so a typo can't hide until
someone runs the lint.
Spelling #
The spelling rule checks prose against the files in [lint.spelling].
Trail doesn't include a dictionary, so the site chooses its language and
supplies the files. Paths are relative to the site root, and a build accepts
them there.
dictionaries lists the words prose can use. A file ending in .dic is a
Hunspell dictionary, read with the .aff file beside it, so one entry covers
a word's other forms: en_US.dic accepts "recognized" as well as
"recognize".
Any other file is a word list with one word on each line, for the names and
terms a general dictionary lacks. A lowercase word in a list is accepted
capitalized too. Lines starting with # are comments.
The rule reports a word that no dictionary, word list, or proper_nouns entry
accepts, with a suggested correction where the dictionary has one:
trail: guide.product/1--basics.topic/100--intro.md:4:9: "kernle": not in the dictionary (did you mean "kernel"?) [spelling]
It leaves alone words that hold a digit or an underscore, which are identifiers, and words written in capitals, which are acronyms ("KACS", "SIDs"). A hyphenated compound passes when each of its parts does.
banned-words lists words and phrases prose must not use, one entry on each
line:
# What to write instead:
e.g. -> for example
utilize*, leverage* -> use
# Why, when the replacement isn't one phrase:
simply, just, of course: don't condescend; cut it
# Banned with no advice:
whilst
Entries match whole words, and a phrase matches across a line break. A
trailing * matches any ending, so utilize* finds "utilizes". An entry with
a capital letter matches exactly. In a lowercase entry, each word matches in
lowercase or with only its first letter capitalized, as in a sentence or a
title: logging in finds "Logging In", but may doesn't find the
specification keyword "MAY". A banned word is reported with its own message,
not as a dictionary miss.
Without dictionaries, the rule checks only banned words.
The field and rule reference is in trail-lint(5).
What counts as prose #
The lint reads sources as written, without building them, so nothing a build generates is checked. Prose is the text a reader sees, so these are never checked as words:
- Code spans and code blocks;
- Raw HTML;
- Link destinations and URLs;
- Citation anchors such as
[*name]; - Frontmatter keys.
An article's frontmatter title and description, and every trail.toml and
link file's title and description, are prose. The root trail.toml isn't
checked.
The built-in rules #
Each rule's name is what turns it on, appears in its reports, and suppresses it.
The field and rule reference is in trail-lint(5).
Some rules are heuristics. They aim never to report what isn't a breach, and so they miss some that are.
title-caseandheading-caseleave alone any word inproper_nouns, and any word whose casing is its own: an acronym ("GXWI", "SIDs"), or a name with a capital or digit inside it ("IPv6"). A word after a colon starts a subtitle and can be capitalized. A lowercase name such as "netd" is fine at the start of a title or heading once it is inproper_nouns.line-lengthexempts tables, code blocks, raw HTML, frontmatter, and link reference definitions. A line is also exempt when it fits once its link destinations and URLs are taken out.hex-caselooks inside code spans, unlike every other rule, because a hexadecimal value in prose is usually written as code:0x1F. Code blocks follow the code's own style and are not checked.serial-commacounts a comma-separated run as a list only when every item but the first is at most three words. It also skips a run that starts with an introductory clause or phrase ("If the key exists, read it and write it"), contrasts ("x, notyorz"), gives examples ("such as A or B"), or quotes. A missed list is better than a wrong report, so it's a warning.
Suppressing a rule #
When a page breaks a rule on purpose, such as a style guide quoting the words it bans, suppress the rule rather than turning it off for the whole site.
For one line, put a comment on the line before it:
- For a stretch of a page, put comments around it:
Name one or more rules, or none for every rule. A comment can sit in a
blockquote (> <!-- … -->) or be indented into a list item.
Put the comments between blocks, not inside a paragraph. A comment line ends the paragraph it interrupts, which changes the page. The comments are invisible on the page, but the page's Markdown mirror shows them, because mirrors show the source as written.
For a whole page or a whole book, name its path in [[lint.ignore]]:
[[]]
= "guide.product/3--conventions.book"
= ["hex-case"]
The path is relative to the site root, and covers a file or everything under a
directory. With no rules, every rule is ignored there.