Code segments and syntax highlighting in Confluence
Yesterday during a documentation session I wanted to add several SQL-queries in a Confluence post. Of course Confluence supports code segments with highlighting etc through the Confluence New Code Macro. It's easy enough to get started with the macro, but specifying parameters turned out to be very poorly documented. This post will hopefully help fill some of the gap!The parameters supported in the Confluence new code macro are the following:
Parameters
- lang
- title
- collapse
- linenumbers
- firstline
- controls
- ruler
- theme
- exportImage
- macro body
Adding a sql code-segment with corresponding line numbers is done with the following code:
{newcode:sql|linenumbers=true|title=SQL Example}
select top 100 *
from customer
where customer_id like '555%'
order by customer_name desc
{newcode}
Resulting in the following formatted segment on Confluence:
Similar for a C# statement in Conflunce I add the following Confluence-code:
{newcode:csharp|linenumbers=true|title=C# Example}
using System;
namespace StaticInitialization
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("At startup");
var a = new ClassA();
Console.ReadLine();
}
}
}
{newcode}
I get the following formatted code in Confluence:
Hopefully you get a better understanding of how to use parameters to format your code segments in Confluence through this post. For more details on the Confluence New Code Macro visit this page.


May 1st, 2011 - 08:36
What wp theme u use?
May 26th, 2011 - 12:58
I use lightword theme