Code blocks
DocsLit provides enhanced code blocks with syntax highlighting, filenames, copy buttons, tabbed groups, and editable variables.
Basic code block
Use standard fenced code blocks with a language identifier:
Every code block includes a copy button automatically.
Syntax highlighting
DocsLit uses Shiki for build-time syntax highlighting. Code blocks are highlighted at parse time, so there is no client-side rendering cost. Shiki supports dual themes -- your code blocks automatically match the page's light or dark mode.
Code theme toggle
Every code block and code group includes a kebab menu that lets readers switch all code blocks between light and dark mode. This setting is independent of the page theme and is saved to the browser for future visits.
You can also force a specific theme on any individual code block:
Fenced code block filename
You can add a filename directly in the fenced code block info string:
This is equivalent to using the filename attribute on wc-code-block.
Code block with filename
Add a filename attribute to show a file header:
Code block with line numbers
Add the linenumbers attribute to show line numbers alongside the code:
Code groups
Group related code examples in tabs using wc-code-group and wc-code-tab:
Editable variables
Use wc-var to create interactive variables that update across all code blocks on the page. Readers click the variable, type their value, and every {{VAR_NAME}} placeholder updates instantly.
Set your API key:
Set your base URL:
Click the variable values above and type your own — watch both code blocks update in real time.
UPPER_SNAKE_CASE by convention. Reference it in code blocks with {{NAME}}.YOUR_API_KEY", give them a field to type it once and see it everywhere.Copy button on code groups
Code groups include a copy button that copies the active tab's content. Readers can copy code from any tab without selecting text manually.
Supported languages
DocsLit uses Shiki for syntax highlighting, which supports all common programming languages including JavaScript, TypeScript, Python, Go, Rust, Java, C, C++, Ruby, PHP, Shell/Bash, SQL, HTML, CSS, JSON, YAML, TOML, Markdown, and more.