The Code Block macro allows you to display source code in your document with the appropriate syntax highlighting. The code block displays on the page as shown below:

public static void main(String[] args) 
{ 
  System.out.println("Hello World!");
}

Using the Code Block Macro

To add the Code Block macro to a page:

  1. In the Confluence editor, choose Insert > Other Macros.
  2. Find and select the required macro.

Speeding up macro entry with autocomplete:

Type { and the beginning of the macro name, to see a list of suggested macros. Details are in Using Autocomplete.

To edit an existing macro: Click the macro placeholder and choose Edit. A macro dialog window will open, where you can edit the parameters of the macro.

You can now type the code block directly into the macro placeholder in the editor. Note that any white space contained in the placeholder is not manipulated in any way by the Code Block macro. This is to provide the writer with flexibility over code indentation.

Parameters

Parameters are options that you can set to control the content or format of the macro output.

Parameter

Default

Description

Syntax highlighting

java

Specifies the language (or environment) for syntax highlighting. The default language is Java but you can choose from one of the following languages/environments:

  • actionscript3
  • bash
  • csharp (C#)
  • coldfusion
  • cpp (C++)
  • css
  • delphi
  • diff
  • erlang
  • groovy
  • html/xml
  • java
  • javafx
  • javascript
  • none (no syntax highlighting)
  • perl
  • php
  • powershell
  • python
  • ruby
  • scala
  • sql
  • vb

Title

none

Adds a title to the code block. If specified, the title will be displayed in a header row at the top of the code block.

Collapsible

false

If selected, the code macro's content will be collapsed upon visiting or refreshing the Confluence page. Clicking the expand source link allows you to view this content. If false, the code macro's content is always displayed in full.

Show line numbers

false

If selected, line numbers will be shown to the left of the lines of code.

First line number

1

When Show line numbers is selected, this value defines the number of the first line of code.

Theme

Default

Specifies the colour scheme used for displaying your code block. Many of these themes are based on the default colour schemes of popular integrated development environments (IDEs). The default theme is Confluence (also known as Default), which is typically black and coloured text on a blank background. However, you can also choose from one of the following other popular themes:

  • DJango
  • Emacs
  • FadeToGrey
  • Midnight
  • RDark
  • Eclipse
  • Confluence

Code examples

See: