Standard code blocks
Use triple backticks with an optional language identifier: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
Addcaption and anchor attributes to include the code block in the List of Code Listings and enable cross-references:
"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
| Attribute | Values | Description |
|---|---|---|
renderAsImage | true, false | Render code as a PNG image in the exported document |
backgroundColor | CSS color (e.g., "#1e1e1e") | Background color of the code block |
width | Number (pixels, 10–2000) | Width of the rendered image |
align | left, center, right | Horizontal alignment |
caption | String | Caption for auto-numbering (List of Code Listings or List of Figures for diagrams) |
anchor | String | Anchor ID for cross-references |
spacingBefore | Number (pt) | Spacing before the code block |
spacingAfter | Number (pt) | Spacing after the code block |
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.