</>MDTooltools

Markdown Code Blocks

Write inline code in Markdown by wrapping it in single backticks (`code`), and multi-line code blocks by fencing them with triple backticks (```) on their own lines. Add a language name after the opening fence for syntax highlighting.

Inline code and fenced blocks

The language tag after the opening fence (js, python, bash, ...) is what enables syntax highlighting in renderers that support it.

Use the `convert()` function.

```js
const pdf = await convert(markdown, { theme: "github" });
```

Showing backticks inside code

To display a backtick inside inline code, wrap it with double backticks. To show a triple-backtick fence inside a block, fence the outer block with four backticks.

`` `backtick` ``

Indented code blocks

Lines indented by four spaces also form a code block in core Markdown, but fenced blocks are strongly preferred: they support language tags and cannot be triggered accidentally by indentation.

Frequently Asked Questions

Why does my code block lose highlighting when converting to PDF?

Many converters parse Markdown with one engine for preview and a different one for PDF generation, dropping the highlighter’s CSS classes in between. MDTool generates the PDF from the same rendered output as the preview, so highlighting survives.

Which languages can be syntax-highlighted?

That depends on the renderer. MDTool ships highlight.js with JavaScript, TypeScript, Python, Bash, CSS, HTML/XML, JSON, YAML, SQL, Rust, Go, and Dart registered.

Try it live

Paste this syntax into the free markdown to pdf converter and see the rendered output instantly — no signup, everything runs in your browser.

Open Markdown to PDF Converter

More Markdown syntax: