• All Posts
  • Code
  • Design
  • Process
  • Speaking
  • Poetry
  • About
D.

August 13, 2022 The Confluence Code Block Macro

When editing Jira text I quickly learned to switch from the “Visual” tab to the “Text” tab where I could simply type my text using Atlassian markdown. I find that this is simpler than pivoting from keyboard to mouse and back again to click a few buttons then back again to the keyboard. Far faster to type the simple macros outright along with the markdown syntax for basic text formatting.

One of the simple macros which ships with the Atlassian Confluence product is the “Code Block Macro”.

The “Code Block Macro” (a.k.a. {code}) wraps text inside an HTML <code>...</code> block.

To use it you can simply enter {code} to open the macro and then {code} again to close the macro:

This is a paragraph of text.

Followed by an unordered list:
- item 1
- item 2
- item 3

And finally a code block:

{code}
{
  "data" : [...],
  "pagination": {
      "limit": 20,
      "token": "REDACTED"
  }
}
{code}

The JSON like blob in between those {code} macro tags will be treated like preformatted text and appear inside a <code> element when rendered on the page.

Properties

Like many Confluence macros, the Code Block Macro exposes custom properties which allow you to configure it’s appearance and behavior.

Two of this macro’s properties are used for syntax highlighting:

Property Default Options
“Language” Supported language values
“Theme” Supported theme values

Configure properties as markdown

Here is a more complete example demonstrating how to append key=value property settings to the start tag of a {code:props} block:

{code:title=This is my title|theme=FadeToGrey|linenumbers=true|language=java|firstline=0001|collapse=true}
This is my code
{code}

Additional Documentation

For more detail check out the Confluence Documentation for the Code Block Macro


back to top

© David Alpert 2025