Skip to main content

Standard code blocks

Use triple backticks with an optional language identifier:
Without a language:

Extended attributes

Append {attrs} after the language identifier to customize rendering:

Render as image

Convert code blocks to PNG images in the exported document. This preserves syntax highlighting exactly as displayed:

Custom background color

Alignment and spacing

Captions and anchors

Add caption and anchor attributes to include the code block in the List of Code Listings and enable cross-references:
This renders with: Listing 1: Configuration interface Reference it elsewhere:
The caption prefix (e.g., "Listing", "Quellcode") and styling are configured in your document’s style settings.

Diagrams

Code blocks with a supported diagram language (e.g., mermaid, plantuml, graphviz) are automatically rendered as images in the exported document. See Diagrams for the full list of supported diagram languages, examples, and options.
Diagram code blocks with a caption are numbered as figures and appear in the List of Figures. Set renderAsImage=false to treat them as regular code listings instead — see Diagrams — renderAsImage.

Attribute reference

The renderAsImage option is particularly useful for PDF/DOCX exports where you want pixel-perfect syntax highlighting. Without it, code blocks are rendered as styled text.