Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do you create a custom syntax highlighting option for the Confluence Code Block macro?

Logan G Hawkes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2012

I've been adding a lot of code samples to Confluence (v3.5.6) pages lately using the Code Block macro. The problem I'm facing is that a lot of the code I'm posting is in languages that aren't listed in the syntax highlighting options (Velocity templates, DOS batch files, Expect, etc). I'd like to create a set of custom syntax highlighting options for these languages but I can't find any documentation on how it's done. Has anyone tried this?

6 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted
Azwandi Mohd Aris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2012

Confluence used to have a Confluence Code Formatting plugin module, whereby you can create your own format for syntax highlighting. However, in Confluence 3.5.x and onwards, the Code Macro plugin has been replaced by New Code Macro plugin, which no longer supports the Code Formatting plugin module.

If you are set for some dirty work, you can probably customise the plugin JAR itself. You will notice that the plugin actually uses the SyntaxHighlighter by Alex Gorbatchev. In particular, each code format is presented by a JS file called as brush. As noted on the brushes page, you might be able to create your own by creating a custom brush.

I have no personal experience in developing a custom brush and incorporate it in the New Code Macro plugin, but hopefully this gives you some pointers!

Azwandi Mohd Aris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2012

Also, the source code for the New Code Macro plugin is at https://studio.plugins.atlassian.com/svn/NCODE/

Jacob Boyko July 30, 2013

I was surprised that Velocity wasn't in the list of languages - it's pretty fundamental to Confluence! The https://marketplace.atlassian.com/plugins/de.scandio.confluence.plugins.pocketquery has velocity syntax highlighting - and a great template editor. Any plans for Confluence to include the same? It would make editing User Macros pretty slick.

trezende October 4, 2018

I am surprised that R also is not one of the default languages.

Like Jason Mercer likes this
Wade Chandler February 13, 2019

Or ABNF considering its use for formats and syntax documentation; definitely the code choices are limited for a doc engine, and seems something that should be easy to customize, even in the cloud (which seems likely most will be using these days). IDEs have solved this for a long time, and seems fitting a service specifically for documentation and editing would as well.

2 votes
Alejandro Conde Carrillo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2015

You can find instructions to do this and examples if the formats in code macro documentation page.

1 vote
Felicity Chapman February 21, 2016

Use of custom brushes is broken in Confluence 5.9. Please vote for https://jira.atlassian.com/browse/CONF-40838 if this affects you.

1 vote
Logan G Hawkes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2015

Distilling the above answers, you can't add your own custom syntax in Confluence versions 3.5 to 5.3 (I'm running v4.3) without some heavy wizardry (see above). If you want to add your own syntax modules you have to upgrade to v5.3 or later.

0 votes
Vladimir Alexiev August 29, 2013

History repeats itself: in Jul 2013, pluggable JS "brushes" were added to NCODE 2.1.0, see

https://ecosystem.atlassian.net/browse/NCODE-18 and

https://ecosystem.atlassian.net/browse/NCODE-19

But this is available only for Confluence 5

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events