Skip to main content

Markdown Code Blocks in Confluence — 190+ Languages

· 4 min read

Every engineering page in Confluence eventually holds code — a curl from the runbook, the config that fixed the incident, the query the dashboard runs. And every one of those snippets has three natural enemies: the language dropdown in the macro dialog, the paste that loses its indentation, and the reader who cannot copy the thing without dragging across line numbers.

Markdown fences solve all three, because they make the code block text you type instead of an object you configure. ```bash, paste, ``` — done, highlighted, copyable. This guide shows the syntax, the theming behavior, and when fences beat the native macro.

Quick answer: To add code blocks in Confluence with Markdown, install Enhanced Markdown for Confluence and use fenced blocks in its macro: ```java, ```python, ```bash — 190+ languages highlighted via highlight.js, GitHub light/dark themes that follow the page, and a copy button for every reader. Free for up to 10 users.

The Syntax — One Fence, One Language Tag

The whole grammar is the fence tag:

```bash
pnpm install && forge deploy
```

Three properties make this the fastest code-block route in Confluence:

  1. The tag selects the highlighter. java, python, sql, yaml, diff — 190+ languages via highlight.js. No dropdown, no dialog, no mouse.
  2. It pastes clean from anywhere. Code from a terminal, an editor, or a GitHub README carries its own fence — drop it in as-is.
  3. It stays portable. Copy the fence back out and it works in a README, a PR description, or an LLM prompt. The block is text; the rendering is a property of the page, not the snippet.

What the Render Gives Readers

The published block is not just colored text:

  • GitHub light and dark themes, picked to match Confluence's palette — and the block follows the page theme automatically, so dark-mode readers get dark code instead of a white rectangle.
  • A copy button on every block — one click onto the clipboard, no gutter-number cleanup, works for read-only viewers.
  • Live re-render while editing — the split preview updates as you type, so a half-typed snippet never renders as a broken artifact.

Copy-Paste Examples for the Four Usual Suspects

A runbook command (bash), a config (yaml), a query (sql), and a bug report (diff):

```bash
curl -s -H "Authorization: Bearer $TOKEN" \
https://api.example.com/v2/deployments?limit=5
```

```yaml
service:
replicas: 3
resources:
requests: { cpu: "500m", memory: "512Mi" }
```

```sql
SELECT status, count(*) AS n
FROM deployments
WHERE created_at > now() - interval '7 days'
GROUP BY status
ORDER BY n DESC;
```

```diff
- timeout: 30
+ timeout: 90
+ retry: { max_attempts: 3 }
```

The diff fence is the quiet hero — before/after config changes render red and green, which turns "we changed the timeout" into something a reader can see.

Fences vs the Native Code Macro

Both exist; they optimize for different moments:

MomentUse
Page is code-heavy, authored like a READMEMarkdown fences — typing speed, no dialogs
Single snippet on an otherwise-visual pageNative macro — no Markdown macro needed
Snippet must live on GitHub tooFences — same syntax in both places
Before/after config changediff fence — color-coded in one block

The honest rule: the native macro is fine for one block. The moment a page holds three snippets — or the snippet also lives in a repo — fences win, because the block is text and text travels.

Runbook Snippet, Start to Finish

The full loop, end to end: install Enhanced Markdown for Confluence, type /markdown on the runbook page, paste the bash fence above, and republish. The next on-call reads highlighted, theme-correct, one-click-copyable code — and when the endpoint changes, you edit one line of text instead of re-screenshotting a block. Free for up to 10 users.

Try Modern Code Blocks for Confluence

Monaco editor, 85+ languages (JSON, XML, YAML, SQL), 50+ themes, diff view, and auto dark/light mode — free for up to 10 users.

Get it on the Atlassian Marketplace