Code
Inline code, fenced blocks, titles, line highlighting, line numbers, diffs, and tabbed snippets.
Inline code#
Use single backticks for short identifiers and commands:
Use docs.json for site configuration.
Fenced code blocks#
Use triple backticks and a language tag for syntax highlighting. Every block gets a copy button automatically.
Common language tags: bash, json, javascript, typescript, tsx,
python, yaml, md, mdx, diff, text. Any
Shiki language works; unknown tags render as
plain text.
Titles#
Add title="..." after the language tag to show a filename bar above the
block. A bare word works as shorthand.
Line highlighting#
List line numbers or ranges in braces to emphasize them:
You can also mark lines inline with a [!code highlight] comment, which is
removed from the output. Append :N to cover the next N lines.
Line numbers#
Add showLineNumbers to number the lines, or showLineNumbers=N to start at
line N. Numbers are decorative: they are excluded from copying and search.
To number every block by default, set
styling.codeBlocks.lineNumbers in
docs.json and use hideLineNumbers on blocks that should opt out.
Diffs#
Use the diff language for a unified diff, where lines starting with + and
- are colored:
To keep full syntax highlighting, annotate lines in any language with
[!code ++] and [!code --] comments instead. Removed lines are skipped by
the copy button so readers get the finished code.
How highlighting works#
- Shiki tokenizes fenced blocks at build time, so no highlighting runs in the browser
- both light and dark colors are embedded once and switched with CSS; choose the
theme pair with
styling.codeBlocks.theme - fenced
<pre>elements are rendered by Shiso'sCodeBlockcomponent, which adds the title bar, line numbers, and copy control
Code groups#
Use CodeGroup when readers should switch between related snippets (for
example package managers or languages):
An optional label after the language tag (or a title prop on the child)
becomes the tab name. See Code Group for
details.