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

Background Shade the Codeblock?

Matthew Oney March 10, 2021

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!

 

1 answer

1 vote
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 10, 2021

Hi @Matthew Oney ,

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

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

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  > 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. 

 

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 . In Cloud however, the code snippets have a prominent grey background and stand out from the page fairly well.

Cheers,
Daniel | Atlassian Support

Matthew Oney March 11, 2021

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!

Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 11, 2021

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

 

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:

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.

Matthew Oney March 12, 2021

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!

Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 12, 2021

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 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 

Matthew Oney March 12, 2021

Ok, I may be able to play around and use that... thank you for your help!!

Like Daniel Eads likes this
Matthew Oney March 12, 2021

Haha hopefully this is the last question(maybe)...

So this appears to work...

## This is an example macro
## @Param 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

Matthew Oney March 12, 2021

Actually it seems to OK if you switch it from 'Escape' to 'Unrendered' , still testing...

Matthew Oney March 12, 2021

Yeah, it seems OK... this will definitely work.  @Daniel Eads  thank you so much for the help!!

Like Daniel Eads likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events