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,

  1. Open your desired Confluence page or blog post, then click the 'Edit' button. The page or blog post opens in edit mode.
  2. Click the Macro Browser icon on the toolbar. The macro browser window opens in the middle of the screen in 'macro selection' mode.
  3. Scroll through the list of macros. Alternatively, start typing part of the name of your desired macro into the search box at the top right of the macro browser window. Macros with a matching name will appear in the main pane.
  4. Click on the desired macro to access its parameters and preview parameter changes ('preview mode').
  5. Set the macro parameters to your requirements. If desired, you can preview these changes by clicking 'Refresh'.
  6. Click 'Insert' to put the macro into the page.

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

Usage with the Wiki Markup Editor

必要な入力項目

表示結果

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

パラメーター

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 (:).

パラメーター

既定

説明

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.


Example 1: Java

必要な入力項目

表示結果

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

public String getFoo()
{
return foo;
}

Example 2: XML

必要な入力項目

表示結果

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

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

Example 3: HTML

必要な入力項目

表示結果

{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>
関連トピック

Working with Macros
Adaptavist User Guide

Take me back to the Confluence User's Guide.