Child pages
  • Code Block Macro
Skip to end of metadata
Go to start of metadata

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.

On this page:

Usage with the Macro Browser

To insert the code block macro into a page using the Macro Browser,

  1. Open the Confluence page or blog post that you want to edit, then click the 'Edit' button.
  2. Click the Macro Browser icon on the toolbar. The macro browser window will open.
  3. Scroll through the list of macros to find the one you want. Alternatively, start typing the macro name into the search box at the top right of the macro browser. Macros with a matching name will appear in the main pane.
  4. Click the desired macro.
  5. Set the macro parameters to your requirements. If desired, you can preview these changes by clicking 'Refresh'.
  6. Click 'Insert' to add the macro onto the page.

(tick) You can also insert macros via autocomplete. For more information, see Using Autocomplete in the Rich Text Editor.

Once you've found the code block macro, click 'insert' to add it to your page.

Usage with the Wiki Markup Editor

What you need to type

What you will get

{code}
public static void main(String[] args) 
{code}

Parameters

Parameters are options that you can include in Confluence macros to control the content or format of the macro output. The table below lists relevant parameters for this macro.

Parameter names are different in the macro browser and in wiki markup. Below we show the macro browser parameter names in bold text, and the equivalent wiki markup parameters in (bracketed) text. If we do not show any parameter name for the wiki markup, then you should leave out the parameter name and simply include the parameter value as the first parameter, immediately after the colon (:).

Parameter

Required?

Default

Description

Syntax highlighting
(language)

no

java

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

  • ActionScript3
  • Bash
  • C# (csharp)
  • ColdFusion
  • C++ (cpp)
  • CSS
  • Delphi
  • Diff
  • Erlang
  • Groovy
  • JavaFX
  • JavaScript
  • Perl
  • PHP
  • PowerShell
  • Python
  • Ruby
  • Scala
  • SQL
  • Visual Basic (vb)
  • XML (including HTML)
  • ... or no syntax highlighting (none).

Title
(title)

no

none

Adds a title to the code macro. If specified, the title will be displayed in its own row at the top of your code macro box.

Collapsible
(collapse)

no

false

If true, 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
(linenumbers)

no

false

If true, a line number will be shown to the left of each line of code, where each number is incremented by 1.
If false, no line numbers are shown.

First line number
(firstline)

no

1

When Show line numbers (linenumbers) is true, this value defines the number of the first line of code.

Theme
(theme)

no

Default

Specifies the colour scheme used for displaying your code. 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.

Be aware that any white space contained between the {code} commands is not manipulated in any way by the Code Block Macro. This is to provide the writer with flexibility over code indentation.

(info) All the optional parameters of the {panel} macro are valid for the {code} macro as well.

Examples


Example 1: Java

What you need to type

What you will get

{code}
public String getFoo()
{
return foo;
}
{code}


Example 2: XML

What you need to type

What you will get

{code:XML}
<test>
<another tag="attribute"/>
</test>
{code}

RELATED TOPICS

Working with Macros

Take me back to the Wikis Help Guide.