Inline code blocks

Hi there!

I am desperately trying to write some inline code within my documentation. In StackOverflow and GitHub I would do `my code`. For code blocks I do ```my code``` which also does not work (but I can work with the code macro). Something like that:

image2016-9-19 22:51:21.png

So how can I do that? Thank you for your support.

8 answers

This has been and continues to be a serious weakness of Confluence and Hipchat.

Confluence is used heavy by software teams. Software teams speak in sentences mixed with code. Forcing us to use code blocks that break the flow of a sentence is a really poor flow.

Slack gets this 100% right. I can type:

We should really consider using `const toolpane =` instead of using `var toolpane =` when we don't expect the variable to change

That should just work. Meaning it will auto-format my inline code snippets. It works on Slack. It works on Github. It is high-time it works on Confluence as well. 

Anything less is just a bad experience. I haven't met a single person yet who disagrees with that.

I could NOT agree more with you Blake.

Confluence is almost certainly 90% used by code teams, but it's code documentation capabilities are not just bad, they are "WORST IN CLASS"

Like 1 person likes this

Hey Atlassian, while I'm on a rant.

The {code} macro.. It just grinds at me each and every time I use it. I can happily edit that inline, but then I just have to grab the mouse, and click the title, click edit, wait (I swear.. 5 seconds.. GEEZE!!), then find syntax highlighting, click the fucking dropdown, find my code.. and click that, and finally I"m fucking done!!

Holy shit - I'm seriously just pissed off THINKING ABOUT HOW PAINFUL THIS IS!

Throw me a bone here--- make this thing have the ability to pick a code block WITH highlighting all from the keyboard.

Peter DeWitt Community Champion Sep 24, 2017

Ed I feel your pain.  Why not open an support request for Confluence with the change you want to see.  That way it can be tracked and voted up by everyone else.

Is the backtick `code` shortcut coming to confluence server any time soon?

Looks like they have fixed it for Confluence Cloud. I entered an open backtick, typed inline code text, then entered a close backtick. The delimited text rendered as code.  See the updates to the issue cited above:

https://confluence.atlassian.com/confcloud/confluence-editing-improvements-945107733.html

https://confluence.atlassian.com/confcloud/keyboard-shortcuts-markdown-and-autocomplete-724764956.html

1 vote

I think you may have answered your own question - use the "code" macro.  Use braces to avoid having to use the mouse to pick stuff.

But that's not inline - am I missing something?

I think I might be, what do you mean by "inline"?

I select the code in a sentence and make it Monospace.

I mean something like this example from StackOverflow:

image2016-9-19 22:51:21.png

I also monospace it like Matt does.

To be clear, start typing your paragraph, then when you want to put in some code, type two open curly braces—the code—and two close curly braces, then continue typing the rest of the text:

I.e. Text {{code}} text

Result: Here comes some code 10 PRINT "Hello" and there is goes.

To get the gray highlight, à la StackOverflow, wrap the code in the Highlight macro:

image2016-9-20 16:9:37.png

image2016-9-20 16:11:43.png

There are so many escaping bugs with double curly braces that they are really unreliable to use in practice...

If only that worked, Mika. But if I'm trying to discuss a variable or macro that starts and end with underscores, double-curlies do nothing:

This is a sentence about the {{_MACRO_NAME_}} macro.

...certainly monospaces the macro name, but also strips the underscores and italicises it. Which is exactly _not_ what I wanted!

Because programmers never use identifiers starting and ending with underscores, do they? :)  (Hint: C, C++, ...)

So far as I can tell, there's no way of inlining code in such a way that formatting characters are not processed. The noformat directive throws its contents into a separate, boxed, paragraph - uuuugly!

Jon Green I'm New Here Jun 28, 2018

Hah! Solution! (Well, in my case anyway.)

Switch to text edit mode, and write the leading and trailing underscores as _ instead.

Yes, it's truly horrible, using HTML character entities rather than, oh, I dunno, human-comprehensible text, but it does work.

Meanwhile - as far as I'm concerned, allowing any formatting primitives to work inside a {{...}} block is a bug. Atlassian, please fix!

Have you tried putting the Code Block macro within a span macro?

Nope, I don't know how to do that. Searched for "span" in macros and couldn't find it. I'm using Confluence in German though.

It's part of the free Content Formatting for Confluence macros from Adaptavist.

Macros are slow and they break the flow of a sentence. I should be able to mix code into a sentence. Github and Slack support this. Why can't Atlassian support it as well? It's simply the way developers write now. 

It's a major product gap imho.

Please comment on these tickets for these issues to get Atlassian to fix this sh!t.

Inline code blockshttps://jira.atlassian.com/browse/CONFCLOUD-57638

Macros modal takes 5-6 seconds to loadhttps://jira.atlassian.com/browse/CONFCLOUD-57639

Wrap inline code blocks in {{double curly braces}}, works for me.

It doesn't work for me in Confluence Cloud. If I write {{double curly braces}} It will show without any format. 

Same. This is a big problem for standard documentation.

Guys.

They've added Markdown support to Confluence Cloud:  entering backticks around the text will render it as inline code (monospace):

https://confluence.atlassian.com/confcloud/keyboard-shortcuts-markdown-and-autocomplete-724764956.html

But it still doesn't add gray highlighting; the code blends in with the rest of the text.  The monospace part was always easy to accomplish.  It's the highlighting that was needed.

:'(

Use the highlight option.  

image.png

Hi Nancy, that only changes the color of the text, not background color / highlight.

sorry - misunderstood. Is this what you want to do?

image.png

Thank you for following up, Nancy.  I don't want to insert a block of code; I want to insert inline code (as the original question asks for).  I haven't been able to figure out how to get it to work with markdown, either (with the monospaced text + gray background).  If you've gotten it to work, I'd love to hear how you did it!  Thanks again.

As Nancy said. Markdown can help here. But its not native. You have to open up the Markup editor (Ctrl+Shift+D) and select Markdown instead of Confluence Wiki. There you can type your code in and wrap it like `foo` in order to get the monospace style.

But I wonder if it is possible to use the CSS div wrapper. Does anyone have knowledge about that?

You can use css and divs to good effect, but as Atlassian plans to deprecate divs as well as other helpful styling, we've decided not to build our pages this way (much as it pains me to have to live within the confines of Confluence Cloud's WYIWYG implementation - I get it, I just don't like it). 

https://confluence.atlassian.com/confcloud/we-re-cleaning-up-the-macro-browser-946028471.html

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 24, 2018 in Confluence

Atlassian Research opportunity with Confluence templates

Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time!   We're looking for people to participate in a   remote 1-hr workshop...

1,102 views 17 14
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you