View Source

{section}
{column:width=60%}{excerpt}
The 'code' macro is a useful way of presenting source code in an easy-to-read format on your Confluence pages. Its use is very straightforward: simply enclose your source code between \{code\} elements.

Here are some examples:{excerpt}

h4. XML

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

h4. SQL

{noformat}
{code:SQL}
SELECT * FROM TABLE1 WHERE ID=0 AND NAME NOT IN (SELECT NAME FROM NAMES)
{code}
{noformat}
gives
{code:SQL}
SELECT * FROM TABLE1 WHERE ID=0 AND NAME NOT IN (SELECT NAME FROM NAMES)
{code}

h4. Java

{noformat}
{code:Java}
package com.atlassian.confluence.admin.actions.macros;

import com.atlassian.confluence.renderer.UserMacroLibrary;

public class UserMacroBean
{
String name;
String template;

public UserMacroBean()
{
}

public UserMacroBean(String name, UserMacroLibrary userMacroLibrary)
{
this.name = name;
this.template = userMacroLibrary.getMacroTemplate(name);
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public String getTemplate()
{
return template;
}

public void setTemplate(String template)
{
this.template = template;
}
}
{code}
{noformat}
gives
{code:Java}
package com.atlassian.confluence.admin.actions.macros;

import com.atlassian.confluence.renderer.UserMacroLibrary;

public class UserMacroBean
{
String name;
String template;

public UserMacroBean()
{
}

public UserMacroBean(String name, UserMacroLibrary userMacroLibrary)
{
this.name = name;
this.template = userMacroLibrary.getMacroTemplate(name);
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public String getTemplate()
{
return template;
}

public void setTemplate(String template)
{
this.template = template;
}
}
{code}
{column}
{column}
{info:icon=false}
For more information about the 'code' macro, please see the [documentation|http://confluence.atlassian.com/x/fiAC].
{info}
{column}
{section}