Skip to content

Code Blocks ​

Fenced code blocks are rendered with monospace font styling.

Syntax ​

markdown
```javascript
function hello() {
  console.log('Hello, world!');
}
```

How It Renders ​

  • Code is rendered in a monospace font
  • A light background is drawn behind the code block
  • Whitespace and indentation are preserved exactly
  • The language identifier (e.g., javascript) is parsed but not used for syntax highlighting in the PDF
  • Code blocks that exceed the page height trigger automatic page breaks

Relevant Options ​

OptionEffect
codeBlockStyling parameters (colors, border, padding, labels)
font.codeThe font family and style used for code (defaults to courier)
codespanStyling parameters mapped to all code blocks and inline spans
page.defaultFontSizeBase font size (code may be slightly smaller)
page.maxContentWidthMaximum width of the code block
spacing.afterCodeBlockSpacing added below the code block

Try It ​

Interactive

Try this element in the Playground — paste the syntax above and click Generate PDF.

Released under the MIT License.