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
Comments (19)
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.?
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
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.
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
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
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.
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
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.
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
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.
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.
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
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.
Could this be a bug? It may also only appear with the theme we are using – I can't tell until I post.
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 :
Regards,
Fennie
Aug 01
Anonymous says:
But within the block the underscores should display as is. Attempting to escap...But within the
this is my\ code
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
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 :
Turns out to be :
Here is _an_ example
Regards,
Fennie
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:
Same code, with a blank line at the end:
In Firefox at least, the first version shows up without the underscore character, though the preview shows it.
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
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
tia Christian
Add Comment