How do I add a custom theme to the code block macro?
Asked by Jim.Creasman:

I'm trying to extend the Code Block macro in Confluence to support a few new languages typically used on the mainframe (e.g., s/390 Assembler). I have successfully added the new language following the instructions in Confluence and SyntaxHighlighter. However, none of the existing color schemes are compatible with how I want the highlighting to look. I see that SyntaxHighlighter also provides for developing custom color schemes. How do I extend the available color scheme choices for Code Block sections in Confluence?


Answers:
author: Shannon S
body: Hello Jim,

Welcome to Atlassian Community. It's nice to meet you!

It's not possible to customize the theme of the code block macro, but I've raised a feature request below for this:

* [CONFSERVER-59314](https://jira.atlassian.com/browse/CONFSERVER-59314) *Ability to customize color theme in code block macro*

In the meantime, you'll be able to use Marketplace add-ons to customize the theme of your code blocks:

* [Atlassian Marketplace](https://marketplace.atlassian.com/search?hosting=server&product=confluence&query=code)

Let me know if you have any questions about that.

Regards,

Shannon


author: Jim.Creasman
body: Thanks for the reply. Unfortunately, none of the plugins in the marketplace do what I need. They don't support the languages I need.

comments: author: Shannon S
body: Hi Jim,

Thank you for letting me know. One of the add-ons for Cloud supports Assembly languages but not the ones for Server.

The custom brush syntax that you use has to adhere to [Custom Brush Syntax](http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/custom.html), but it looks like you can include colors that way. Have you already tried calling the colors you need with CSS and that doesn't work?

Regards,

Shannon


author: Jim.Creasman
body: Yes, after adding the custom brushes I've been playing around with the colors and available themes. My goal is to make the code look like it does in the native z/OS terminal window since the code snippets we are documenting will be viewed by this set of developers. None of the color choices get it right 100%.

The SyntaxHighlighter on which the Code Block macro is based supports adding custom themes as well as custom brushes. My suggestion (and what I believe you are saying in the ticket you opened) is to also expose this interface to anyone wishing to customize the macro. I've added myself to the watch list for any future updates. In the mean time I'm exploring writing my own macro for this purpose.

Thanks,

Jim


author: Shannon S
body: Hi Jim,

Yes, I'm sorry, I did mean via the UI, so I've updated the feature request to state this.

Good luck on working using the brush syntax. If you end up with anything you'd like to share, please feel free to share it here!

Regards,

Shannon


author: Shane Presley
body: I have a similar requirement to replicate the highlighting color scheme from a UI that my users are accustomed to and have hit this same wall.   

It seems that in the years since this thread the links to the [Custom Brush Syntax](http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/custom.html) has gone dead and the brush files described in <https://confluence.atlassian.com/doc/code-block-macro-139390.html>
> You can see examples in `<install-directory>/confluence/includes/js/third-party`.

are from a much older version of the library (1.5) than what is shipped with Confluence (3.0). I managed to extract the actual brushes used by Confluence from the browser inspector which was extremely tedious.

The SyntaxHighlighter library has moved on to v4 and is now at <https://github.com/syntaxhighlighter/>, documentation is still pretty sparse though. The library itself does support custom themes but not Atlassian.

It's just a CSS file

```
/* module-key = 'com.atlassian.confluence.ext.newcode-macro-plugin:sh-theme-confluence', location = 'sh/styles/shThemeConfluence.css' */
```

and I would be more than happy to just be able to upload my own css with the brush. Icing on the cake would be the ability to specify a default theme per brush.


Tags: confluence-server

server