This documentation relates to the latest version of Confluence.
If you are using an earlier version, please go to the documentation home page and select the relevant version.

Code Block Macro

All Versions
Click for all versions
Confluence 2.9 Documentation

Index

You need to edit in 'Wiki Markup' mode to include macros in your page.

The Code Block Macro allows you to display source code in your document with the appropriate syntax highlighting.

All the optional parameters of the {panel} macro are valid for {code} too.

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

Code Block Macro

{code:language} ... code ... {code}
OR
{code} ... java code ... {code}


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>
RELATED TOPICS

Working with Macros
Adaptavist User Guide

Take me back to Confluence User Guide

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.
  1. Nov 30, 2007

    Anonymous says:

    Is it possible to add more languages? Like bash/ksh/sh, jython, etc.?

    Is it possible to add more languages? Like bash/ksh/sh, jython, etc.?

    1. Dec 02, 2007

      Choy Li Tham says:

      Hi, Unfortunately, Confluence does not support this feature. However, there is ...

      Hi,

      Unfortunately, Confluence does not support this feature. However, there is an improvement request currently being tracked in the following:

      Please do cast your vote to increase its popularity and add yourself as a watcher to the updates. Also, feel free to add comment in the improvement to truly reflect your ideas. Thanks.

      Regards,
      Choy Li

    2. Dec 02, 2007

      David Soul [Atlassian] says:

      While neither list bash or jython, you may wish to check out the http://confluen...

      While neither list bash or jython, you may wish to check out the http://confluence.atlassian.com/display/CONFEXT/New+Code+Macro and http://confluence.atlassian.com/display/CONFEXT/Pygments+Code+Macro plugins which support a wider range of languages and have a more pluggable interface for new languages.

  2. Feb 14, 2008

    Anonymous says:

    Why is there a scroll bar on the right hand side of the code block that doesn't ...

    Why is there a scroll bar on the right hand side of the code block that doesn't even slide? Whenever I create a code block it makes a scroll bar that is just the size of the block! Thanks

    1. Feb 14, 2008

      Choy Li Tham says:

      Hi, Did you meant to say that you would like to control the scrollbar display i...

      Hi,

      Did you meant to say that you would like to control the scrollbar display in the Code Block macro? If that is the case, there is an improvement request being raised at the follwoing:

      If you are keen on this improvement, please do cast your vote to increase its popularity and add yourself as a watcher for future updates. Also, feel free to add comments to reflect the importance of this improvement.

      Regards,
      Choy Li

  3. Feb 28, 2008

    Anonymous says:

    Are there any plans to provide syntax highlighting directly within the Wiki Mark...

    Are there any plans to provide syntax highlighting directly within the Wiki Markup editor for Atlassian wiki markup?  It would make it a lot easier to edit pages if basic syntax highlighting were present in that view.

    1. Feb 28, 2008

      Ming Giet Chong says:

      Hi, There is an improvement request being raised at: http://jira.atlassian.c...

      Hi,

      There is an improvement request being raised at:

      Please feel free to cast your vote and add yourself as a watcher for future updates. Thanks.

      Regards,
      MG

  4. Jun 13

    Anonymous says:

    The XML code formatter doesn't colorize correctly when an element is split over ...

    The XML code formatter doesn't colorize correctly when an element is split over 2 or more lines.

    <element type="not_split" colorized="correctly">
    </element>
    <element type="split" 
             colorized="incorrectly">
    </element>
    1. Jun 17

      Ming Giet Chong says:

      Hi, Please raise a support ticket at the code macro's issue tracker for further...

      Hi,

      Please raise a support ticket at the code macro's issue tracker for further investigate to this issue:

      Regards,
      MG

  5. Jul 11

    Treg Anderson says:

    Hi, I have added this comment to the New Code Macro comment section but I have s...

    Hi, I have added this comment to the New Code Macro comment section but I have seen this problem using this macro as well.

    I am having a problem using the New Code Macro on IE 7.0.  If I have one long line of text within the {code} tags the macro produces a scrollbar at the bottom of the code box but it covers up the single line of text. I am currently using IE 7.0 to enter this comment and when I shrink the width of the browser the scroll bar pops up over the text on the example below.

    This is some text that could cause a horizantal scroll bar with a narrow enough window

    With the window wide enough the scroll bar goes away and the text can be seen.

    Is this a bug that is known and is in the process of being fixed? I looked for the source code to take a look at it here but there doesn't seem to be any to download.

    1. Jul 14

      Tony Cheah Tong Nyee says:

      Hi Treg, Thanks for reporting this. I have raised a bug report on behalf of thi...

      Hi Treg,

      Thanks for reporting this. I have raised a bug report on behalf of this at:

      Feel free to add yourself as a watcher so that you will be notified if there is any update on the issue. Also, you may add comments on the bug report to truly reflect the problem that you are having.

      Cheers,
      Tony

  6. Jul 28

    Anonymous says:

    When I create a single line code block macro, the underscore character is hidden...

    When I create a single line code block macro, the underscore character is hidden when viewed with Firefox. It appears normally in the Preview and Rich Text editors, but when viewed regularly, it doesn't work.

    Here is _an_ example

    Could this be a bug? It may also only appear with the theme we are using – I can't tell until I post.

    1. Jul 30

      Fennie Ng says:

      Hi, In Confluence Wiki Markup, underscore represents italic . Thus, you should ...

      Hi,

      In Confluence Wiki Markup, underscore represents italic . Thus, you should not see underscore for the words as it will be rendered to italic form. If you would like to display underscore, you can use a slash to escape it :

      Here is \_an\_ example
      

      Regards,
      Fennie

      1. Aug 01

        Anonymous says:

        But within the block the underscores should display as is. Attempting to escap...

        But within the

        block the underscores should display as is.
        
        Attempting to escape it with a backslash \ causes the backslash to be displayed
        this is my_code
        
        

        this is my\ code

        1. Aug 01

          Anonymous says:

          _ _ _ \_ My last post didn't work out how I planned - but it looks like the u...
          _ _ _ \_

          My last post didn't work out how I planned - but it looks like the underscores are displayed in this version of the wiki - but not ours

          1. Aug 06

            Fennie Ng says:

            Hi, Are you using the markup in Rich Text Editor or Wiki Markup Editor? I am us...

            Hi,

            Are you using the markup in Rich Text Editor or Wiki Markup Editor? I am using the following code in Wiki Editor and it looks fine :

            Here is \_an\_ example
            

            Turns out to be :

            Here is _an_ example

            Regards,
            Fennie

    2. Sep 24

      Anonymous says:

      This appears to be a bug:  if you have an underscore character in a code bl...

      This appears to be a bug:  if you have an underscore character in a code block or a noformat block, it will not appear unless there is another line below it.

      Single line:

      % psql my_database admin
      

      Same code, with a blank line at the end:

      % psql my_database admin
      
      

      In Firefox at least, the first version shows up without the underscore character, though the preview shows it.

      1. about 2 hours ago

        Ming Giet Chong says:

        Hi, Could you please raise a support ticket at https://support.atlassian.com fo...

        Hi,

        Could you please raise a support ticket at https://support.atlassian.com for further investigation? Do provide the screen shot of the expected result. Thanks.

        Regards,
        MG

  7. Aug 19

    Christian Nesemann says:

    Hi, can anyone tell me the css-selector which allows me to modify the code-bloc...

    Hi,

    can anyone tell me the css-selector which allows me to modify the code-block macro ?
    I want to add a horizontal scrollbar to it. Firefox and IE7 already work fine but not so IE6.

    e.g.
    for this code

    {link-to:dashboard}Dashboard{link-to} >{report-info:content:space|link=true}>{report-on:content:ancestors|separator=" > "}{report-info:content:title|link=true}{report-on}>{report-info:content:title|link=true}
    \\

    i get this html

    div class="code panel" style="border-width: 1px;">div class="codeContent panelContent">
    <pre class="code-java">{link-to:dashboard}Dashboard{link-to} &gt;{report-info:content:space|link=<span class="code-keyword">true</span>}&gt;{report-on:content:ancestors|separator=<span class="code-quote">" &gt; "</span>}{report-info:content:title|link=<span class="code-keyword">true</span>}{report-on}&gt;{report-info:content:title|link=<span class="code-keyword">true</span>}
    \\</pre>
    /div>/div>

    tia Christian

Add Comment