Background Shade the Codeblock?
Asked by Matthew Oney:

Is there no way to make the background for the macro code block a different color? Or any other way to make it stand out?

It just looks odd with only the box around it. I've seen this asked in alot of other places but I haven't seen a solution yet.

Thanks!


Answers:
author: Daniel Eads
body: Hi [@Matthew Oney](/t5/user/viewprofilepage/user-id/4237016) ,

The code block macro in Confluence Server / Data Center comes with several themes. By selecting the macro, you can click the Edit button to modify the macro's options:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/133986iFC6C4FA1CAAE045E/image-dimensions/213x203?v=v2 "image.png")

Aside from selecting a language for syntax highlighting and enabling line numbers, you can choose one of several themes. All the themes except 'Eclipse' and 'Confluence' come with dark backgrounds. Here's a screenshot of the snippet above using the Midnight theme:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/133984iD6B092775C627471/image-dimensions/270x259?v=v2 "image.png")

You can even set a particular language as default for syntax highlighting, and change the default theme. (It's the 'Confluence' theme if this hasn't been configured yet).

1. Go to ![](https://confluence.atlassian.com/doc/files/747833194/747833195/2/1517274813281/cog.png) \> **General Configuration** \> **Configure Code Macro**.
2. Select a **Default Theme** and **Default Language**.
3. Choose **Save**.

If you're adding the macro using wiki markup, you can also pass options like the theme in as parameters. [Details are available in the code macro's documentation.](https://confluence.atlassian.com/doc/code-block-macro-139390.html)

On the Confluence Cloud side of things, the code macro has been replaced by the code snippet in the new editing experience. Currently code snippets aren't customizable (again, this is only Cloud) but [a feature request for customizing them is fairly active](https://jira.atlassian.com/browse/CONFCLOUD-66437) . In Cloud however, the code snippets have a prominent grey background and stand out from the page fairly well.

Cheers,  
Daniel \| Atlassian Support

comments: author: Matthew Oney
body: Got it, that's awesome and will definitely work!

Last question - In docuwiki there is a add-on for copy/paste; you left click in the code block and it copies the contents to your clipboard, is there something similar in confluence?

Thank you for your help!


author: Daniel Eads
body: Just noting another difference between Confluence Cloud and Confluence Server here for the benefit of other folks coming across this answer. On the Cloud code snippet, there's a copy button in the upper right:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/134153i911B311C1C9EEE02/image-size/large?v=v2&px=999 "image.png")

However on Server, there's not a built-in button like this. I've checked the marketplace and found two code block apps that do provide this:

* [Code Painter for Confluence](https://marketplace.atlassian.com/apps/1220198/code-painter-for-confluence?hosting=server&tab=overview)
* [Advanced Codeblocks for Confluence](https://marketplace.atlassian.com/apps/1211159/advanced-codeblocks-for-confluence?hosting=server&tab=overview)

But it is pretty quick to "select all" with the out-of the-box code macro. Just double-click somewhere in the code block (after the first line) and all the text in the code block will be selected. From there you can cmd/ctrl+C or right-click to copy. Not as fast as a single button, but still faster than dragging to select all the text.


author: Matthew Oney
body: Actually this is crazy... so I can only have the 'default' code macro?

I can't have one for python that I call with like ...  
{pyth...

one for powershell code block

{powe...

There's no way to have more than one codeblock?

Thanks for you patience and help with this!


author: Daniel Eads
body: Oh, interesting use-case! Most people call {code} and then use the Edit button on the macro to change the options (including the language). Using the Default Language setting at the top of this thread, you can change which language the block will pre-set when you just call {code}.

But you're right - it's all {code} and there aren't specific macros for each language. Using wiki markup (outside the editor), you can pass in the language you want when creating the macro... but it's still not as simple as just a macro called {powershell} like you mentioned.

Checking around marketplace again, there's no apps that add multiple macros for all the various languages you might want to use. They all start with one macro, and you need to edit the options to choose a non-defaulted language.

One possibility might be to [create your own user macro](https://confluence.atlassian.com/doc/writing-user-macros-4485.html) that calls the code block macro with whatever parameters you want - and create similar user macros for each of the languages you want to shortcut. I haven't personally seen an implementation of this, but I did find a (rather old) thread here on Community where folks discussed something similar: [Preformatting code blocks and tables using user macros](https://community.atlassian.com/t5/Answers-Developer-Questions/Preformatting-code-blocks-and-tables-using-user-macros/qaq-p/548042)


author: Matthew Oney
body: Ok, I may be able to play around and use that... thank you for your help!!


author: Matthew Oney
body: Haha hopefully this is the last question(maybe)...  

So this appears to work...

## This is an example macro  
## [@Param](/t5/user/viewprofilepage/user-id/1345631) Title:title=Title\|type=string\|desc=Title  
\<ac:macro ac:name="code"\>  
\<ac:parameter ac:name="title"\>Python\</ac:parameter\>  
\<ac:parameter ac:name="language"\>python\</ac:parameter\>  
\<ac:parameter ac:name="theme"\>eclipse\</ac:parameter\>  
\<ac:parameter ac:name="linenumbers"\>true\</ac:parameter\>  
\<ac:parameter ac:name="firstline"\>1\</ac:parameter\>  
\<ac:parameter ac:name="atlassian-macro-output-type"\>BLOCK\</ac:parameter\>\<ac:plain-text-body\>\<!\[CDATA\[$body\]\]\>\</ac:plain-text-body\>

\</ac:macro\>

buuuuut when I save it I get -

![confluencecode.png](https://community.atlassian.com/t5/image/serverpage/image-id/134283i360434B10F294631/image-size/large?v=v2&px=999 "confluencecode.png")


author: Matthew Oney
body: Actually it seems to OK if you switch it from 'Escape' to 'Unrendered' , still testing...


author: Matthew Oney
body: Yeah, it seems OK... this will definitely work. [@Daniel Eads](/t5/user/viewprofilepage/user-id/1527694) thank you so much for the help!!


Tags: confluence-server

server