Confluence Docs 3.0 : Code Block Macro This page last changed on Aug 16, 2009 by ggaskell. 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 Usage with the Wiki Markup Editor Parameters Examples ## Usage with the Macro Browser To insert the code block macro into a page using the Macro Browser, Open your desired Confluence page, then click the 'Edit' button. The 'Edit Page' mode opens. Next, click the Macro Browser icon on the editor toolbar. The Macro Browser will open in the middle of the screen. In the Macro Browser, type the name of your desired macro into the search box at the top right of the window. Macros with a matching name will appear in the centre pane. Click on the desired macro to see its options screen. Here, you can set the macro parameters then 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
What you need to type | What you will get
--- | ---
    {code}
    public static void main(String[] args)
    {code}
     public static void main(String[] args)
## Parameters Parameters are settings for Confluence macros that allow the user to control their content or presentation. The table below lists relevant parameters for this macro. Parameter names are displayed differently in the macro browser interface and in wiki markup. Below, parameter names used in the macro browser are indicated in Bold text, while their equivalents in wiki markup are indicated in (`bracketed`) text. If the latter is not shown, then in wiki markup, the parameter's name should be omitted and only its value should be added immediately after the colon symbol (`:`).
Parameter | Default | Description
--- | --- | ---
Code Language (`code:`) | 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. 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 Guide.

Document generated by Confluence on Nov 05, 2009 23:35