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!");
}

On this page:

Usage with the Macro Browser

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

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}
 public static void main(String[] args) 

Parameters

Parameter

Default

Description

Code Language
(lang)

Java

Specifies the programming language for syntax highlighting. The default language is Java but you can specify JavaScript, ActionScript, XML, HTML or SQL instead.

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}

public String getFoo()
{
return foo;
}

Example 2: XML

What you need to type

What you will get

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

<test>
<another tag="attribute"/>
</test>

Example 3: HTML

What you need to type

What you will get

{code:HTML}
<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html;">
<TITLE>xmldemo_002</TITLE>
</HEAD>
</HTML>
{code}

<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html;">
<TITLE>xmldemo_002</TITLE>
</HEAD>
</HTML>
RELATED TOPICS

Working with Macros
Adaptavist User Guide

Take me back to the Confluence User's Guide.