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!
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:
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:
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).
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
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, I may be able to play around and use that... thank you for your help!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 -
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually it seems to OK if you switch it from 'Escape' to 'Unrendered' , still testing...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.