It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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.

11 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 # people like this

Spot on, the markup used by Atlassian is bad.  MS Teams, GitHub, Slack and nearly everything in inline code snippet is as simple as using back-ticks. Why does Atlassian think they need their own version of Markup? ...why not use something already tried and true; that actually is useful!

Like Michael Tuchman likes this

the new editor experience allows formating via backticks (e.g. `my inline code`). You can also select your inline code and press CTRLSHIFT+m on Windows.

UPDATE: Backticks started working for me two minutes after I posted this comment. I appreciate the respect.

It is absolutely bananas that backticks don't do the trick in 2019. The only reason Confluence can get away with this is that it's a de facto monopoly.

Like Peter Flynn likes this

The code has moved on in the last 2 years.  Move with it.

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

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

Like olisteadman likes this
Like # people like this

Thanks for opening up that ticket Ed.  Nice to see that Atlassian has taken this soo seriously that it has been sitting for nearly two years and still awaiting verification.  That's Atlassian's way of saying thanks for using our product and giving feedback/opening an issue... we just don't care!  More reason to move to another platform; although I'm tied to this at work but I use better products for all projects outside of my 9-5.

Like Peter Flynn likes this

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?

Like Wayne Ritchie likes this

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

Like Tor Nizan likes this

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

Like # people like this

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!

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!

@Nic Brough {Adaptavist} 

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

Are you kidding me?  "There's no such thing as a dumb question." ...yeah, that there, is a dumbass question! 

Humm, what does "inline" mean?  Well, it is INLINE with the rest of the content; as opposed to BLOCK.  

Nic, yo brough, `const hasAnyKnowledgeOfDevelopment: boolean = false;`, that is INLINE with the rest of the text.  FYI

```
if (you see something that is block scoped) {

  // you can assume that it is NOT inline
}

```

offtopic: @Wayne Ritchie are you seriously attacking Nic for a comment that he as made over 3 years ago?!?

@Andreas Nie-Fröhlich 
Nope, just amazed a "Community Leader" doesn't know what inline means in the context.  Hopefully over the past few years they've managed to figure out the difference between inline and block; if not, I just didn't want them to continue on not knowing something so fundamental.  ...especially as a Community Leader...  ...and yet there are still no `inline code highlighting` abilities for the platform; making the text mono doesn't count! Yes, YEARS later!

<sigh>  It's not my fault you can't understand the question.

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.

Like # people like this

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.

Like # people like this

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

Like Michal Orlik likes this

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 WYSIWYG implementation - I get it, I just don't like it). 

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

I would suggest that Jira comments are just as important, if not more, of a place to support robust code-style text entry. I am going with the {{{color:green}MY CODE TEXT{color}}} hack - thanks for that, @nancywilson - for now, but it's a LOT of extra cruft to have to write in.

Ok, so I think what @Vicki Foss & others are looking for is a simple way to create this kind of highlighting:

https://cimpress-support.atlassian.net/wiki/spaces/CI/pages/188743804/File+Prep

I think it's easiest to use the HTML macro and apply standard code notation to get the desired effect.  Really not such heavy lifting.

<p>You can <span style="background-color:#c5d9f7;"> <code>highlight inline code sections</code></span> using the HTML macro and standard code notation for span tags.</p>

Sorry if this is a stupid question, but can this be easily done while you're typing, without resorting to the mouse etc? I'm a bit new to Confluence, but....

Many thanks

As an aside, I'm looking to do this in a cloud-based instance, so we don't have html macro available there :-(

 

You (or your admin) can add the HTML macro to your Confluence instance.

Thanks for your reply Nancy, but the 'standard' HTML macro can't be enabled on a cloud instance, as I understand it - see https://community.atlassian.com/t5/Confluence-questions/HTML-Macro-for-Confluence-Cloud/qaq-p/104061.

I always use {code} ... as much code as you need here .... {code}

 

You can specify syntax formatting with {code:sql}.....{code} etc

 

similar to {panel} but implies {noformat} and syntax highlighting. 

 

Or, is that specific to Jira?

@John McCabe , I'm not sure about HTML, although I'm pretty sure I've used an HTML block somewhere on my cloud confluence, but there is a free Markdown extension you can use instead, which is probably better to use than HTML anyway.

https://marketplace.atlassian.com/apps/1212654/render-markdown?hosting=cloud&tab=overview

also see my post above from Sept. 2018 :

There is native Markdown support in Confluence Cloud: 

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

Thanks for those replies. I'll take a look at them but, for reference, what I'm looking to achieve is something like when you#re in the editor and type:

{span:style=border: 1px solid #c5c5c3; border-radius: 3px; background-color: #eef;}

Then, in the box that opens, enter something like:

`cd /home/john/subdir`

It's similar to what you (Nancy) linked to before with the red text and the grey background, but a little prettier :-)

Pretty counts!

it has been mentioned before, I summarize it again:

In the new editor experience of Confluence (tested on Cloud Edition) you can use CTRL+SHIFT+m to trigger monospace formating. It will have a grey background and will look like inline code.

Also you can use `my inline code` (backticks) to trigger the monospace formating.

See the documentation on keyboard shortcuts

on  the Mac, it's cmd+shift +m, but it does not render highlights, only monospace.  Does the highlighting render on Windows?

Yes, the background is highlighted with a light grey color.

I'm seeing no highlight on Windows :(

Hi, folks.

Good news! It works in the new editor.  Atlassian sent this email to admins 14 October:

To our Confluence admins,

It's time to get your teams using the new editing experience in Confluence Cloud which enables anyone to create beautiful, powerful pages effortlessly. We will be rolling this new experience out as the default way to create new pages in the coming weeks.


Create with the new experience
1. Create a new page in your Confluence Cloud instance.
2. Select the template labeled "Try the new editing experience" from the create modal.
3. Voilà! You're ready to start creating a page with the new experience.


Try out the best parts of the new experience
• Use the slash command (/) to add anything from tables to images, and keep focused with in-context toolbars.
• Our new live macros provide previews of your content so you can see exactly how content will look after publishing.
• Use the new media experience to add files from Dropbox, Google Drive, or even GIPHY. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence Cloud

What's New in Confluence Cloud – October 2019 Edition

Hey there! When you can pack so much information onto a Confluence page, it can be challenging to whittle down what’s most important. Here are a few of our favorite hacks for finding need-to-know i...

62,167 views 63 151
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you