Templates

Templates form Moth's only string-composition system. Square brackets can join short values, format Markdown or HTML and compose larger layouts with slots, wrappers and control flow. Template $ directives remain owned here; the accepted general directive family is documented at Directives.

Other languages often split this work across concatenation, interpolation and a separate template language. Moth keeps one typed String result and lets the compiler fold it when every input comes from compile time.

Choose the explanation level: Template basics

Template basics

Templates form Moth's string-building engine.

name = "Priya"

greeting = [:
    Hello, [name]
]

Square brackets create the template.

The colon separates its head from its body.

A nested template inserts a value from the surrounding scope.

Templates can build plain text, Markdown, HTML, CSS or another string-based format. They may be finished during compilation or built at runtime.

HTML pages come from @entry.moth. A bare direct [...] must fold into static page output. A direct ~[...] is an explicit runtime body fragment. Builder metadata uses direct bare [$in name: ...] inserts. See Entry metadata and builder slots for page metadata. Assigned or returned templates remain ordinary String values.

Entries and page fragments. HTML pages come from directories that contain @entry.moth. A bare direct top-level [...] must fold into static page output, while

~[...] deliberately publishes a runtime body fragment.

Direct const root $in inserts supply builder metadata. See Entry metadata and builder slots for their rules.

Templates create owned String values.

They use square brackets. Collections and maps use braces.

name = "Priya"

greeting = [:
    Hello, [name]
]

Head and body

A colon separates the template head from its body.

["prefix": body]

The head separates each meaningful item with a comma, including directives. Source directives use separate attachment rules. The head may contain:

  • a value or helper template
  • directives
  • slot declarations and insert contributions
  • final if or loop control-flow suffixes

The final if suffix conditionally includes one body for a true Bool or a present option capture. The final loop suffix repeats its body with an ordinary loop header. Template control flow excludes else, else if, break and continue. Use ordinary Moth code for richer decisions.

The body contains authored text and nested templates.

Authored .moth templates must close with a closing square bracket.

Truncated heads, bodies, nested children and directive-argument templates are syntax errors.

Capture and text

A template may read visible values from its surrounding scope.

Inside a template body:

  • backticks are ordinary body text
  • backslashes are ordinary body text
  • formatter directives decide how authored text is transformed

Double-quoted string slices still use normal escaping in expression position.

Literal delimiters in output

To render a literal open or close square bracket inside a template body, insert a string slice:

content = [: ["[literal]"]]

Use string insertion when a template needs literal square brackets.

Compile-time and runtime forms

A template may:

  • fully fold to a compile-time string
  • remain as runtime string construction

The source-level result stays an owned String.

Templates do not become source-visible function values.

Runtime fixed binary-float interpolation and compile-time folding use the same Moth formatter.

MON data boundary

Unevaluated template syntax is not a MON string literal. A folded compile-time template and an evaluated runtime template are each an ordinary serialisable String for their producer; which side produced the text never changes document validity. There is no automatic MON interpolation. See MON format.

Page fragments

A direct top-level template contributes output only in @entry.moth.

  • direct bare [...] must be compile-time foldable and becomes a static fragment
  • direct ~[...] reserves a runtime fragment slot, even if its content can fold
  • a bare direct fragment with runtime-dependent content is an error rather than an implicit runtime fallback
  • a direct bare [$in name: ...] insert routes to a builder-registered destination; a runtime-marked named insert is invalid
  • ordinary direct const fragments and runtime body fragments render into the page body
  • a template assigned to a binding or returned from a function remains a String value and does not become a page fragment by itself

Only a direct root insert reaches builder routing. A nested or stored insert stays ordinary template composition. Runtime top-level named builder inserts are not part of the contract.

A [$note: ...] child in a template body discards its balanced body without creating a fragment. Ordinary assigned, returned and nested templates keep their own const/runtime rules. The old direct #[...] entry-fragment spelling is removed.

Page assembly is owned by Project Structure. Const-template rules, including builder slot contributions, are owned by Const templates. See Entry metadata and builder slots.

Choose the explanation level: Template directives

Template directives

$ is the general directive marker. This page covers template-specific meanings. For general directive ownership and syntax, see Directives.

The compiler owns template directives and formatters. Source modifiers such as $export and $config have separate targets. Builders cannot register directives.

Template directives begin with $.

content = [$md:
    # A heading

    This body is Markdown.
]

Common directives include:

  • $slot for $slot, $slot name and $slot 1 declarations
  • $in name: to fill one named slot
  • $before ... and $after ... to wrap direct children
  • $fresh to skip one parent wrapper
  • $md for Moth Markdown
  • $raw for unformatted text
  • $note for discarded comment templates in a template body
  • $html, $css, $escape_html and $code under every builder

Template heads separate expressions and directives with commas, and a directive name cannot repeat in one head. $doc and $todo are source annotations, not template-head directives.

A slot declaration occupies its head alone. Each $in directive fills one named slot. See Template slots and Child wrappers for composition details.

A formatter applies only to the template that declares it. Nested child templates choose their own formatter.

$ is the general directive marker. This page owns template-specific directive semantics. General ownership, context, argument and diagnostic rules live in Directives.

Template-head directives modify their containing template, regardless of whether the head also has ordinary expressions. Their syntax does not change the placement rules for following-construct source modifiers.

Every template directive is compiler-owned and available under every builder. There is no builder extension point, so availability never depends on the selected builder:

  • the compiler defines the directive set
  • a builder contributes root-slot destinations through direct const $in slots, which are not directives
  • an unknown directive is a syntax or rule error

Frontend directives

$before value and $after value:

  • add a prefix and suffix to each direct child. Either directive may be omitted
  • each may appear once per head, so a repeated $before or $after is rejected
  • accept a compile-time String or constant template wrapper and reject runtime-dependent values
  • values may contain named slots but not default or positional slots. Child insertion is implicit
  • produce no wrapper for structurally absent output, but wrap a selected empty String
  • wrap a direct child loop's aggregate output once

$fresh:

  • opts one child out of the immediate parent's before/after wrapper

$slot:

  • declares $slot, $slot name, $slot 1 and an optional = <compile-time String> default
  • must be the only meaningful item in its head and never opens a body

$in name:

  • contributes content to one named slot
  • accepts a bare name only, not a String expression or a positional target
  • can appear only once per head
  • a routed contribution, including an explicitly empty one, suppresses that slot occurrence's default

$note:

  • discards its balanced body without evaluating it or producing output
  • is the sole template comment directive, valid only as a child of a template body

$doc and $todo annotate following source declarations or statements instead of template heads. They are invalid here. See Directives.

$raw:

  • preserves authored body content and whitespace without a formatter

$md:

  • applies Moth Markdown formatting

Builder-root inserts

On an active application entry root, a direct top-level const $in is a builder contribution rather than a template-slot helper. The selected builder registers its destination names. Only a direct root insert routes. A nested, stored or aliased insert remains ordinary template composition.

Builder destinations are builder-interpreted. The HTML builder registers title, description, lang, favicon, body_style, stylesheets and head. See Const templates and Entry metadata and builder slots.

Formatter directives

The compiler owns these template-formatting directives. They are available under every builder:

$html:

  • treats the body as raw HTML content

$css:

  • applies balanced-body CSS checking and formatting

$escape_html:

  • escapes HTML-sensitive body content

$code "language":

  • highlights a code body
  • removes formatting-only indentation from multiline bodies using the first content line as the baseline
  • preserves indentation relative to that baseline
  • escapes HTML-sensitive characters in text mode without applying syntax classes
  • suppresses nested child-template interpretation inside the code content

Formatter directives remain constrained to formatting and composition contracts. They cannot rewrite functions, change nominal identity, mutate HIR or weaken language safety. For the shared directive grammar and its single-operand rule, see Directives.

Formatter scope

Formatting directives do not flow automatically into nested child templates.

A nested child that needs $md, $raw, $html, $css, $escape_html or $code declares that formatter itself.

Moth template files are the exception:

  • a nested template with no explicit directive defaults to $md
  • any explicit directive overrides that default

Combining items in one head

A template head can hold several comma-separated items, including expressions and directives. Unlike source directive runs, template heads always require commas between meaningful items. Every directive name may appear at most once in the same head, including $fresh. Most directives combine freely with other items, but structural directives can require the whole head.

$slot and $note must be the only meaningful item in their head. A slot declares where content arrives from elsewhere, while a note discards its balanced body. Either combined with another item has nothing to act on:

-- Error: the slot shares its head with a string
card = [:
    <section>["prefix", $slot]</section>
]

Put the extra content in the surrounding template body instead:

card = [:
    <section>prefix[$slot]</section>
]

Each template head can contain at most one formatter. $md, $raw, $html, $css, $escape_html and $code each decide how the body is formatted, so the compiler rejects a second formatter, including a repeat of the same one:

-- Error: both directives format the body
io.line([$md, $raw: Hello])

$in name can sit beside other items, but it can appear only once per head. Each insert sends its body to one named slot, so use one insert template for each slot you fill:

[card:
    [$in title:Hello]
    [$in footer:Goodbye]
    Body content
]
Choose the explanation level: Template slots

Template slots

A slot is a place where another template supplies content.

card = [:
    <h1>[$slot title = "Untitled"]</h1>
    <section>[$slot]</section>
]

[card:
    [$in title:Welcome]
    This is the card body.
]

The named title slot receives Welcome.

The default slot receives the body text.

Without an insert, title shows its Untitled default while an empty default slot renders nothing. Each slot occurrence owns its own compile-time String default, and an explicitly empty insert still suppresses it.

Positional slots use $slot 1 and are filled by loose head contributions. $in targets a named slot only and has no positional form. Slots that receive no content and have no default become empty strings.

See Template slots for declaration forms, positional routing, stored inserts and runtime contributions.

Slots let one template receive content from another.

Declaration and insert forms

card #= [:
    <h1>[$slot title = "Untitled"]</h1>
    <section>[$slot]</section>
]

[card:
    [$in title:Welcome]
    Body content
]

The declaration and insert forms are:

[$slot]                     -- default slot
[$slot = "Fallback"]        -- default slot with a default
[$slot name]                -- named slot
[$slot name = "Fallback"]   -- named slot with a default
[$slot 1]                   -- first positional slot
[$slot 1 = "Fallback"]      -- positional slot with a default
[$in name:body]             -- contribution to one named slot

Names and positions are bare source tokens, not String expressions or lexical value bindings. $slot "title" and $slot 0 are invalid. A position is a positive whole number. A $slot declaration must be the only meaningful item in its head and cannot open a body.

$in accepts a bare named target. It is not a String expression and it has no positional form, so $in "title" is invalid. Each $in directive fills one named slot and can appear once per head.

Defaults

An occurrence can hold a compile-time String default, including a literal, a constant binding, a cast or a structural resource path:

fallback #= "Draft"

card #= [:
    <h1>[$slot title = fallback]</h1>
    icon=[$slot image = @assets/icon.svg]
    alt=[$slot alt = "Icon"]
]

A default is an ordinary compile-time String value. It is not an arbitrary expression evaluator and it is not a template wrapper value. A fully folded template constant is an ordinary String and is accepted. A wrapper template with unresolved slots is not. A nonconstant or non-String default is diagnosed at the declaration.

Each slot occurrence owns its own default, even when another occurrence uses the same key. A routed contribution, including an explicitly empty one, suppresses that occurrence's default. An occurrence with no default and no routed contribution renders empty. Repeated named occurrences consume the same routed contributions but may fall back independently:

card #= [:
    first=[$slot title = "First fallback"]
    second=[$slot title = "Second fallback"]
    body=[$slot = "Body fallback"]
]

unset #= [card]
chosen #= [card:[$in title:Chosen]]

Both title occurrences show Chosen in chosen. In unset they show their separate fallbacks. Multiple contributions to one named slot concatenate in source order. Contributions containing A- and B- fill both title occurrences with A-B-. An explicitly empty insert still counts as routed.

An application with routed or loose content closes its own unfilled defaulted occurrences: an enclosing template cannot fill them later. A head-only reference with no fill stays an open wrapper. Slots authored in supplied content still belong to their own enclosing composition.

Positional slots

Positive integer slots receive loose head contributions. The number is a declaration target, not an insert target:

image = [:
    <img src="[$slot 1]" alt="[$slot]">
]

[image, "logo.png": Site logo]

The first loose contribution fills slot 1.

The remaining loose body content fills the default slot.

A positional declaration may also carry a default. Positional slots are never filled by $in.

Routing rules

  • Loose contributions fill positional slots in ascending numeric order.
  • Remaining loose contributions go to the default slot when one exists.
  • Loose content that cannot be assigned is an error when no default slot exists.
  • An occurrence with a default renders that default when nothing is routed to it.
  • An unfilled occurrence without a default renders as an empty string.
  • Repeated slots replay the same contribution.
  • Named inserts target only their named slot and never fill positional or default slots.
  • Multiple contributions to one named slot concatenate in source order.
  • An unknown named insert target is diagnosed at the receiving template.
  • One application may combine named, positional and default contributions.
  • Formatting-only body whitespace around named inserts is not a loose contribution; an explicitly supplied empty or whitespace String remains a contribution.

Builder root slots

A builder can register named destinations for direct top-level const inserts. On an active entry root, a direct const $in routes to that builder destination rather than to an ordinary template slot. Only a direct root insert routes. A nested, stored or aliased insert remains ordinary template composition.

Builder slot values are builder-interpreted. Their fallbacks and output policies belong to the selected builder, not to the language-level occurrence default rule. See Const templates and Entry metadata and builder slots.

Stored named inserts

Named inserts can be prepared in a binding and passed as loose contributions through an immediate parent:

card = [:
    <h1>[$slot title]</h1>
    [$slot]
]
stored_title #= [$in title:Stored title]
rendered #= [card: [stored_title] Body]

The stored helper is flattened into the immediate parent's slot-routing stream. An insert with no matching immediate parent remains invalid.

Imported wrappers, re-exports and constant-record projections preserve their slot defaults and routing.

Runtime contributions

Runtime-capable templates support slot contributions from selected template if branches and template loop bodies.

AST prepares the slot routing before HIR.

Runtime lowering appends the routed contributions through normal string accumulators. Presence comes from routing, not from whether rendered content is nonempty.

Unresolved slot or insert artefacts after routing are invalid template structure.

Choose the explanation level: Child wrappers

Child wrappers

$before and $after wrap each direct child with a prefix and suffix.

list #= [$before [:<li>], $after [:</li>]:
    <ul>
        [$slot]
    </ul>
]

This is useful for lists, table rows and repeated layout elements.

Either directive is optional, and each may appear once per head. Values must be compile-time Strings or constant template wrappers. A constant template may contain named slots, filled by the enclosing application. If a value contains a slot, it must be named: an explicit default or positional slot is rejected. The child insertion point is implicit.

row #= [$html:<tr style="[$slot row_style]">]
rows #= [$before row, $after [$html:</tr>]:[$slot]]

[rows:
    [$in row_style:background: red;]
    [: first]
]

Conditions or loops producing no output do not emit a wrapper. An explicitly selected empty String still does.

Use $fresh when one child should skip the immediate wrapper:

[list:
    [: wrapped]
    [$fresh: [: not wrapped]]
]

$before and $after add a prefix and suffix around each direct child template.

list #= [$before [:<li>], $after [:</li>]:
    <ul>
        [$slot]
    </ul>
]

[list:
    [: one]
    [: two]
]

Each direct child becomes one list item.

The composed order is prefix content, the direct child, then suffix content. The child insertion point is implicit because only one is allowed.

Values and named slots

Each directive is optional, and either may be used alone. Each may occur once per head, so a repeated $before or $after is rejected. Both may appear in the same head. The assignment marker is required, so $before or $after without = is invalid.

A value is a compile-time String or a constant template wrapper. A plain String is literal text. A compile-time String may also retain structural resource pieces, which survive composition and resolve in the output context. A constant template wrapper may contain named slots, which the enclosing application fills. Its unresolved slot identity and structural resource pieces survive composition.

row #= [$html:<tr style="[$slot row_style]">]
rows #= [$before row, $after [$html:</tr>]:[$slot]]

[rows:
    [$in row_style:background: red;]
    [: first]
    [: second]
]

The $in row_style contribution belongs to the enclosing rows application and fills the wrapper's named slot. It is not routed to either child.

An occurrence can own a default in the wrapper value. The default applies only when no contribution reaches that occurrence:

rows #= [$before [$html:<tr style="[$slot row_style = "background: white;"]">], $after [$html:</tr>]:[$slot]]

Only named slots may appear in a $before or $after value. An explicit default or positional slot anywhere in the value, including in a nested template, is rejected at the offending slot. The child insertion point is implicit.

Runtime-dependent expressions and values that are neither compile-time Strings nor constant template wrappers are rejected at their authored span. For a template value, normal template body whitespace applies, including a space immediately after its body colon.

No output and loops

A false or absent condition and a zero-iteration loop emit no wrapper. A selected empty String still counts as output and is wrapped. A direct child loop is wrapped once around its aggregate output. Put a wrapper inside the loop body to wrap each iteration.

Direct-child scope

The wrapper applies only to direct children.

Literal body text is not individually wrapped.

A selected child becomes an opaque contribution to its parent.

The parent's wrapper does not descend into that child's nested templates.

A nested helper may declare its own $before and $after wrapper.

This keeps row, cell, list and layout helpers from leaking wrappers into deeper content.

The same rules apply through const folding, runtime lowering, imports and re-exports.

$fresh

$fresh opts one child out of the immediate parent wrapper.

[list:
    [: one]
    [$fresh: [: two]]
]

The first child receives the list-item wrapper.

The second child does not.

$fresh:

  • affects one child
  • affects only the immediate parent wrapper
  • does not change sibling behaviour
  • does not disable wrappers declared deeper inside the child
Choose the explanation level: Template control flow

Template control flow

A template if includes its body only when a Bool condition is true.

[if signed_in:
    Welcome back
]

An option-present capture includes its body only when the option has a value. The captured value is available inside that body.

[if maybe_name is |name|:
    Hello [name]
]

Template if has no else or else if form. Template loops repeat content with an ordinary loop header, including its signed by step and bindings.

[loop names |name|:
    <p>Hello [name]</p>
]

Template control flow has no break or continue markers. Ordinary Moth statements still have their own if, else, break and continue forms. Template bodies build lazily at runtime unless they are const-required.

Templates support if and loop as final head suffixes.

If the head already contains a value, helper or directive, add a comma before the control-flow suffix.

[if show:
    Visible
]

[card, if show:
    Visible inside card
]

Template if

A template if conditionally includes one body. Its selector is either a Bool condition or an option-present capture. The captured value is scoped to the body.

[if show:
    Visible
]

[if maybe_name is |name|:
    Hello [name]
]

Runtime templates evaluate only the selected body. A false condition or absent option produces structural no-output. Template control flow has no else or else if form, and template loops have no break or continue controls.

For richer decisions in .moth code, choose a value with ordinary value-producing if and then interpolate it:

maybe_name String? = none
name = if maybe_name is |present_name| then present_name else "guest"
greeting = [: Hello, [name]]

This value-producing form belongs at supported receiving sites such as a declaration; it is not an expression inside template interpolation. A .mtf body remains const-required and cannot call runtime functions as a general replacement.

Template loops

Template loops repeat their body using the ordinary loop-header families:

  • conditional loops
  • collection loops
  • numeric ranges
[loop items by 2 |item, index|:
    [index]: [item]
]

[loop 10 to 0 by -2 |value|:
    [value]
]

Collection and range loops may bind the current value and an optional second binding. A collection loop's second binding is the actual source index, while a range loop's second binding is the zero-based iteration ordinal. Both have type I32.

Collection and range headers accept the ordinary signed by step. A collection step's sign selects its starting item and direction, while a range step's sign selects direction. In runtime templates, their source or bounds and their step are evaluated once before iteration. Conditional loop conditions are checked before each iteration. Iterations concatenate directly without separators. Compile-time zero steps are rejected in both forms, while a runtime template's dynamic zero step fails before the first iteration.

Wrappers and no-output

A wrapper in the owning loop head wraps the complete aggregate once. Place a per-iteration wrapper inside the loop body.

A false or absent conditional, a false conditional loop and a zero-iteration collection or range loop produce structural no-output. Shared head wrappers and parent before/after wrappers are skipped in those cases. A selected body with no content is still selected, so its own head wrapper may render an empty wrapper. A runtime expression that produces an empty String still produces output.

Fallible work and slots

Postfix ! inside selected runtime template content propagates from the enclosing function. Catch blocks are not template expressions. Runtime slot applications remain valid inside a conditional body or loop body after normal slot routing.

Compile-time template control flow, inactive-body validation and iteration limits are specified by Const templates.

Choose the explanation level: Markdown formatting

Markdown formatting

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 URLs
  • scheme: 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.