Use $md when a template body should be formatted as Markdown.
content = [$md:
# Welcome
This text becomes **formatted content**.
]
Small inline code spans use one backtick on each side.
Use $code "moth" or another language name for a full highlighted code block.
Moth Markdown stays small. It does not support fenced code blocks or pipe tables.
Section IDs
Add a bare @#id at block start or after whitespace to set the HTML id of the heading, paragraph or list item that contains it. The marker is zero-width. An ID starts with a Unicode letter and continues with Unicode letters, digits, _ or -, and its authored case is preserved.
content = [$md:
## Getting started @#getting-started
Jump back to @#getting-started (Getting started).
]
A paragraph containing only a marker renders a standalone empty span.
Unmarked headings have no id. $md does not check page-wide uniqueness, add generic HTML attributes or validate fragment targets. Plain .md does not use section markers.
Advanced covers the full rules.
$md applies Moth's small Markdown flavour.
It is intentionally not a full CommonMark implementation.
content = [$md:
# Title
Use **clear names** and @./other-page (helpful links).
]
Supported block forms
- headings:
# through ###### - paragraphs separated by blank lines
- unordered lists:
- items - ordered lists:
1. items - links:
@./relative-path (link text), @/site-route (link text) or @https://... (link text) - emphasis:
**bold** and *italic* - section IDs:
@#id on a heading, paragraph or list item
Explicit section IDs
A bare @#id section marker sets the HTML id of the heading, paragraph or list item that contains it. Place it at block start or after Markdown whitespace. It is zero-width and adds no visible text. When removal would leave doubled or edge whitespace, one adjacent separator is removed, so A @#x B renders A B.
An ID starts with a Unicode letter and continues with Unicode letters, digits, _ or -. Authored case and Unicode spelling are preserved; there is no lowercasing, slugification, URL escaping or suffix generation. The marker ends at whitespace, the end of its inline block or a star run that closes active emphasis. A marker embedded directly after other text, such as prefix@#id, stays literal.
content = [$md:
# Release notes @#release-notes
@#summary A paragraph can own an ID too.
- Install the package @#install
]
A paragraph containing only a marker has no paragraph element to decorate, so it renders a standalone empty span:
content = [$md:
@#release
]
Inside a list, a nested item owns its own marker. A marker in item continuation text decorates the outer <li>, never a child item or an inner paragraph. A marker followed by a link-label introducer is decided as a link first; an incomplete label keeps the existing literal fallback.
The compiler does not check document-wide uniqueness or resolve fragment targets. Keep IDs unique within the final page. Generic HTML attributes, whole-element links and an id template helper are not part of $md.
A labelled link is unchanged: @#getting-started (Getting started) is a link, not a marker. Marker-like text inside a link label or inline code stays literal. A malformed ID or two markers on one block is a source error. Unmarked headings have no id.
content = [$md:
See @#getting-started (Getting started).
See @./guide#getting-started (Getting started).
See @/docs/guide#getting-started (Getting started).
]
The first target stays on the same page, the second addresses a relative page and the third addresses a site route. A site-route target keeps its fragment after the origin prefix.
Link targets
A Moth-aware link target is a URL, never a file value. It is never resolved against the filesystem, copied, watched or tracked. Markdown link parsing is not file discovery. A file value inside $md is written as an ordinary nested Moth expression instead, not as a link target. See File values.
A target beginning with a single / is a site route. It renders through the site root, so the project's configured origin is applied for you.
content = [$md:
Read the @/docs/packages (Packages) reference.
]
Under origin #= "/moth" that renders href="/moth/docs/packages", and href="/docs/packages" when no origin is configured. This is the same site-root piece that bare @/ produces in expression position. See File paths.
Every other target renders literally:
./ and ../ relative targets# fragment and ? query targets// protocol-relative URLsscheme: absolute URLs such as https://
A relative target is already correct from the page that contains it, and an absolute or protocol-relative URL addresses another origin entirely, so neither takes the site root.
Link labels
Separate a link target from its parenthesised label with spaces or tabs, or one line break with optional spaces or tabs on either side. At least one separator character is required. LF, CRLF and lone CR each count as one line break. A second line break or intervening non-whitespace content prevents association. Links remain within the current inline block and cannot cross an opaque template or expression boundary.
Inline code
Inline code uses paired isolated single backticks on one Markdown line.
It renders as a normal HTML code element.
Inside an inline code span:
- authored whitespace is preserved
- HTML-sensitive authored characters are escaped
- emphasis is not parsed
- links are not parsed
Not supported:
- empty code spans
- repeated backtick runs
- unmatched backticks
- multiline code spans
- variable-length delimiters
- fenced code blocks
- Markdown-level backtick escaping
Use $code "language" for highlighted code blocks.
Literal template syntax in inline code
Backticks format Markdown after Moth has parsed nested templates. They do not protect square brackets from Moth's template parser. To show Moth syntax literally inside inline code, insert a quoted String:
-- Source in a .mtf file or a $md template body:
Static fragment: `["[...]"]`
Runtime fragment: `["~[...]"]`
Builder slot: `["[$in title:...]"]`
For example, ~[...] displays the literal runtime-fragment syntax without interpreting it as a nested template. Backslashes in template bodies are ordinary text, so they cannot escape template brackets.
Dynamic content boundaries
A dynamic expression anchor may appear inside a parent-authored code span.
$md does not inspect that expression's rendered output.
A child template is an opaque formatting boundary.
A parent Markdown span cannot begin before a child and end after it.
Tables
Markdown pipe-table syntax is not part of Moth Markdown.
Inside .mtf content, use a structured list.
When a website page needs a visual table, build it in the owning .moth page with Moth table helpers.
Do not rely on pipe-table text rendering as a table.
Related content formats
Moth template .mtf files use an implicit compile-time $md template.
Plain .md files use the separate raw Markdown content path and do not understand @#id section markers.
See Moth template files and Plain Markdown for those file contracts.