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
page.defaultFontSizeBase font size (code may be slightly smaller)
page.maxContentWidthMaximum width of the code block
page.lineSpaceSpacing around 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.