Code Blocks
Configure Shiki-powered fenced code rendering, languages, themes, line numbers and full-bleed code, and use fence meta for titles, line marks and terminal sessions.
Code Blocks
Fenced code blocks are rendered with Shiki during the Markdown compile pipeline. The browser receives finished HTML and does not need a client-side syntax highlighter.
Preferred Code Config
Use the top-level code namespace:
1import { DEFAULT_CODE_LANGS, payloadMarkdown } from 'payload-markdown'2 3payloadMarkdown({4 code: {5 enhanced: true,6 fullBleed: false,7 langs: [...DEFAULT_CODE_LANGS, 'latex', 'r'],8 lineNumbers: true,9 shikiTheme: 'github-dark',10 },11})
Use collection-level code when one collection needs different behavior:
1payloadMarkdown({2 code: {3 lineNumbers: true,4 },5 collections: {6 posts: {7 code: {8 langs: [...DEFAULT_CODE_LANGS, 'latex'],9 lineNumbers: false,10 },11 },12 },13})
Options
enhanced: applies the plugin's normalized code block renderer, defaulting totruefullBleed: lets fenced code blocks extend beyond the normal content width on larger screenslangs: replaces or extends the Shiki language listlineNumbers: controls visible line numbers when enhanced rendering is enabledshikiTheme: selects the Shiki theme, defaulting togithub-dark
shikiTheme is intentionally separate from directive themes.
Default Languages
DEFAULT_CODE_LANGS includes:
1bash, cpp, java, js, ts, jsx, tsx, json, python, rust, html, css, yaml, sql
bash also highlights fences tagged sh, shell, zsh, or shellscript.
Extend it when authors need additional Shiki languages:
1import { DEFAULT_CODE_LANGS, payloadMarkdown } from 'payload-markdown'2 3payloadMarkdown({4 code: {5 langs: [...DEFAULT_CODE_LANGS, 'go', 'php', 'vue'],6 },7})
If a fence uses an unknown language, the renderer falls back to plain text highlighting instead of failing the page.
Language Fences
Use standard fenced code blocks with a language identifier:
1```ts2export function sum(a: number, b: number) {3 return a + b4}5```
The language hint is passed to Shiki during Markdown compilation.
Fence Meta
Words after the language on the opening fence line are the block's meta. They add a title, mark lines, and change how one block is shown:
1```yaml title="orbit.yaml" {3-4} ins={6}2remote:3 name: origin4 url: https://example.com/orbit.git5 mode: mirror6sync:7 interval: 15m8```
| Token | Meaning |
|---|---|
title="…" |
A caption above the block. Single quotes and a bare word (title=orbit.yaml) work too. The title is text, never HTML |
{3-4}, {1,3-5} |
Highlighted lines: 1-based, ranges inclusive |
ins={6}, del={2-3} |
Inserted and removed lines, marked with + and − in the gutter as well as a tint |
wrap |
Long lines wrap under the line number instead of scrolling |
nolines |
No line numbers for this block |
terminal |
A terminal session: commands and their output (see below) |
Tokens are separated by whitespace; a quoted title or a {…} group may hold spaces. Groups of the same kind merge ({1} {3} is {1,3}), the last title wins, and lines past the end of the block are ignored.
A fence needs a language to carry meta: the first word is always the language. Use text for a block that should not be highlighted:
1```text title="Output" nolines2Synced 3 remotes.3```
A titled block renders as a figure, so the caption stays attached to the code:
1<figure data-code-figure class="md-code-figure">2 <figcaption class="md-code-title">orbit.yaml</figcaption>3 <pre class="shiki …">…</pre>4</figure>
Untitled blocks keep rendering as a bare <pre>. Line marks are classes on the line spans (md-line-highlight, md-line-ins, md-line-del) and wrap adds md-code-wrap to the <pre>. The tints are translucent, so they read on light and dark code themes; override them with --pmd-code-highlight, --pmd-code-ins and --pmd-code-del, and the caption with --pmd-code-title-bg and --pmd-code-title-color.
Terminal Sessions
terminal separates what a reader types from what the program prints:
1```bash terminal2$ orbit remote add origin https://example.com/orbit.git \3 --mode mirror4Added remote "origin".5$ orbit sync6Synced 1 remote.7```
- A line starting with
$is a command. The prompt is its own span, which cannot be selected. - A command line ending in
\continues on the next line. - Every other line is output: plain text, never highlighted as shell.
The copy button copies only the commands, without prompts, one per line (continuation lines kept), so the copied text runs as is. A terminal block with no command lines copies everything. The <pre> carries data-terminal.
With Enhanced Rendering Off
With code.enhanced: false the title, line marks, wrap and the terminal structure are still rendered and styled; nolines has nothing to remove, since that mode shows no line numbers.
Meta Diagnostics
- An unknown token is ignored and reported once as
unknown-code-meta. It is information only and never fails a strict check, so meta written for other tools (copy,filename=…) does no harm. - A malformed range (
{a-b},{5-2},{0}) or an unterminated quoted title (title="a b) is ignored and reported asinvalid-code-meta, also information only.
Neither ever fails a strict check: content written before fence meta was read (```jsx {props}) keeps validating.
The editor linter and the skills' checker report the same two diagnostics.
Enhanced Rendering
Enhanced rendering provides:
- Shiki tokenization
- normalized spacing and layout
- optional line numbers
- empty-line normalization
- copy button behavior from the renderer client helper (commands only for
terminalblocks) - server-rendered HTML output
Disable it when you want output closer to raw Shiki:
1payloadMarkdown({2 code: {3 enhanced: false,4 },5})
When enhanced is false, line numbers are disabled even if lineNumbers is true.
Full-Bleed Code
Use fullBleed when long code examples should visually break out from normal prose width:
1payloadMarkdown({2 code: {3 fullBleed: true,4 },5})
Renderer-level overrides use the same namespace:
1<MarkdownRenderer2 code={{ fullBleed: true }}3 markdown={content}4/>
Legacy Aliases
The old config.options shape still works:
1payloadMarkdown({2 config: {3 fullBleedCode: true,4 options: {5 enhancedCodeBlocks: true,6 langs: [...DEFAULT_CODE_LANGS],7 lineNumbers: true,8 theme: 'github-dark',9 },10 },11})
Prefer:
1payloadMarkdown({2 code: {3 enhanced: true,4 fullBleed: true,5 langs: [...DEFAULT_CODE_LANGS],6 lineNumbers: true,7 shikiTheme: 'github-dark',8 },9})