Shortcut for "code block" macro in Confluence editor
Asked Answered
N

3

30

We use confluence for documentaion but i find very time consuming to select the code macro; it's a 5 step process. Even typing the macro by hand is not efficient.

In the Stack Overflow editor all we have to do is select the text and press a button or hit ctrlK, and the text is formatted as code.

Is there a way to do this in Confluence?

Naaman answered 26/11, 2012 at 2:26 Comment(0)
K
46

even typing by hand is also not efficient

I use the code macro extensively and always use the autocomplete feature by typing { and choosing 'Code Macro' from the list (It's enough to type co for the code macro). This is a very efficient.

Of course a keyboard shortcut would be faster, but there is no shortcut for the code macro. (AFAIK there is no keyboard shortcut for a specific macro at all)

Kress answered 26/11, 2012 at 8:57 Comment(2)
There is an issue with using {code} from the editor where formatting is lost when code is pasted in.Swill
I use {noformat} the same way, but do find it cumbersome! You can also copy a {noformat} code block to your clipboard and then paste it over and over.Potage
S
11

I use Ctrl-Shift-D then wrap the text in {code}.

This also fixes the problem with formatting being stripped from pasted text. In Confluence 5.x if you edit a page, you can type {cod<enter} and it puts a Code Block box on the page, but when code is pasted into this box it can strip out end of line characters.

  1. Open the Insert Markup window using Ctrl-Shift-D
  2. Paste in your code as plain text
    This way the formatting is not stripped out.
  3. Add {code} tags.
Swill answered 3/12, 2014 at 2:44 Comment(2)
you can also specify the language, so {code:language=bash} for ex.Begotten
In theory, typing "{code:bash}" is supposed to do the same thing. (The colon gets sort of auto-added when the editor recognizes the brace-c-o-d-e keystrokes.) In practice, the code highlighting changes, but if later opening the block's "edit" popup, the syntax language field will be blank. Changing the dropdown to Bash adds the "language=" part.Receptacle
I
5

You can also type three back ticks ``` to create a code block as you would in vanilla Markdown. This creates an empty code block very quickly. I never have with problems with formatting when pasting code in this way.

The one irritating feature of this method is that you can't specify the language as you do in Markdown, you have to select the language from a list.

Ideograph answered 12/12, 2019 at 5:58 Comment(2)
seems like for this a special version or plugin is needed, does not work in our internal confluence.Arrington
Thanks, this way of doing it seems to work with the new Confluence page editor. The old way of typing {code} stopped working for us with the new editor.Effieeffigy

© 2022 - 2024 — McMap. All rights reserved.