Add callouts and diagrams #
On this page
Prompt:
Put a warning above the step that deletes the output folder, and draw the build flow as a diagram.
Also works: "The [!NOTE] on the setup page shows as plain text." "Our diagrams render as code."
For a callout, start a block quote with a marker such as [!WARNING] on a line of its own (step 1). For a diagram, write a fenced block marked mermaid (step 2), and, to have the site draw it, run npm install mermaid in the folder where you run tzdocs (step 3). Then check and build (step 5).
What your AI tool does #
- Turns a note or a warning into a block quote that opens with a marker, such as
[!WARNING], on a line of its own. - Writes a diagram as a fenced block marked
mermaid, in Mermaid's text syntax. - Runs
npm install mermaidin the folder where it runs tzdocs, so the build includes the script that draws diagrams in the reader's browser. - Runs
tzdocs check --source docs, corrects what it reports, and builds. - Asks before it installs Mermaid if the project keeps its dependencies under review.
What you need #
- Which notes are tips, which are warnings, and so on.
- Whether the site should draw diagrams, or show them as code.
Before your AI starts #
Your AI coding agent checks these things before it starts.
- A corpus that passes the check and builds (Getting started).
Steps #
1. Add a callout #
Start a block quote with a marker on a line of its own. Callouts use GitHub's syntax, so a page reads the same in its repository.
> [!WARNING]
> The build replaces the whole output folder.
The five markers are [!NOTE], [!TIP], [!IMPORTANT], [!WARNING], and [!CAUTION], in any letter case. The build renders the quote as a callout titled Note, Tip, Important, Warning, or Caution, with a colored bar at its left.
Tip
A callout can contain anything a block quote can: paragraphs, lists, and code blocks.
The marker must be the whole first line, so > [!NOTE] Read this stays an ordinary block quote. Each type's color is a custom property, such as --docs-callout-note, which Style the site shows how to change.
2. Write a diagram #
A fenced block marked mermaid contains a diagram in Mermaid's text syntax.
```mermaid
graph TD
Source[A folder of Markdown] --> Build[tzdocs build]
Build --> Site[A static site]
```
A diagram block takes no title and no line set, because a drawn diagram has no caption and no lines to emphasize. The block below shows as a diagram if this manual was built with Mermaid, and as code otherwise.
graph LR
accDescr: Write a page, then tzdocs check, then tzdocs build.
Write[Write a page] --> Check[tzdocs check] --> Build[tzdocs build]
3. Install Mermaid #
To draw diagrams in the browser, the build needs Mermaid installed. Run this in the folder where you run tzdocs.
npm install mermaid
A Mermaid installed in a folder above that one serves as well. The build looks in that folder and each one above it, never at NODE_PATH or a global install. The build copies Mermaid's browser file into the site as mermaid.min.js, and each page with a diagram loads it. The site serves its own copy, so diagrams need no other site. The reader's browser draws each diagram, in dark colors if the reader's system prefers a dark scheme.
Without Mermaid, each diagram block shows as code, and the build prints one notice that tells you to run npm install mermaid. The build still succeeds.
A mermaid block inside a markdown-only section is no diagram: the HTML page leaves it out, and the build needs no Mermaid for it.
4. Or show diagrams as code #
To keep every mermaid block as code even if Mermaid is installed, pass --diagrams-as-code to the build. The pages then load no Mermaid file, and the build prints no notice.
tzdocs build --source docs --out site --diagrams-as-code
5. Check and build #
Run tzdocs check --source docs. It reports a bracketed word that is not one of the five markers, such as [!WARN], which stays a block quote. It also reports a title, line set, showLineNumbers on a mermaid fence. The renderer used on this website also reports copy= on a diagram. The npm package tzdocs 0.13.0 reports copy= as unrecognized metadata.
Correct each line it reports, then build and open the diagram page in a browser. The check validates the fence metadata, not the Mermaid diagram syntax. If the diagram does not render, inspect the browser's console and correct the diagram source; a clean source check alone does not prove that it renders.
Expected result #
Each callout shows its title in its type's color, above the rest of the quote. With Mermaid installed, each diagram page draws its diagrams once it loads, and the tree has mermaid.min.js at its root. Without Mermaid, or with --diagrams-as-code, each diagram shows as a code block.
Refusals #
None of these stops the build. Refusals and findings gives the exact text.
| Message | Exit code | Cause | Remedy |
|---|---|---|---|
unknown callout type in <file> — [!<word>] stays a block quote; the types are NOTE, TIP, IMPORTANT, WARNING, and CAUTION |
1 from the check | A block quote opens with a bracketed word that is not one of the five markers. | Use one of the five markers. |
a mermaid diagram takes no title or line set |
1 from the check | A mermaid fence carries title="..." or a line set in braces. |
Remove them from the fence line. |
a mermaid diagram takes no showLineNumbers key |
1 from the check | A mermaid fence carries showLineNumbers. |
Remove it from the fence line. |
a mermaid diagram takes no copy key |
1 from the check | A mermaid fence carries copy=. |
Remove copy= from the fence line. |
notice: <N> pages hold mermaid diagrams, shown as code — run "npm install mermaid" in this folder to draw them. |
0 | Mermaid is not installed where the build runs. | Run npm install mermaid there, or pass --diagrams-as-code. |
Related #
- Highlight a code block covers every other fenced block.
- Page source gives the exact rules for callouts and diagrams.
- Output describes the markup and the files the build writes for them.