How to format an inline code in Confluence?

2019-01-29 19:11发布

How can I format an inline code in Confluence like this? I mean, not a separate code block, but just inline classname, for example.

14条回答
Summer. ? 凉城
2楼-- · 2019-01-29 19:32

I found formatting with colors a bit trickier as Confluence (5.6.3) is very fussy about spaces around the {{monospace}} blocks.

Creating Colored Monospace with Wiki Markup

As rendered by Confluence

查看更多
贼婆χ
3楼-- · 2019-01-29 19:32

To format code in-line within your text, use the '`' character to surround your code. Usually located to the left of the '1' key on your keyboard.

Example:

`printf("Hello World");`

Same delimiter as Stack Exchange!

查看更多
何必那么认真
4楼-- · 2019-01-29 19:38

By default Confluence renders monospaced text with transparent background. You can edit global CSS to add grey color. From Confluence manual:

  1. Choose the cog icon at top right of the screen, then choose Confluence Admin.
  2. Choose Stylesheet.
  3. Choose Edit.
  4. Paste your custom CSS into the text field.
  5. Choose Save.

Custom CSS for displaying grey background in monospaced blocks:

code {
    padding: 1px 5px 1px 5px; 
    font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
    background-color: #eeeeee;
}

If you're using Confluence OnDemand (cloud):

  1. Click the cog/gear in the bottom of the sidebar on the left
  2. Select Look and Feel
  3. Click the Sidebar, Header and Footer tab
  4. Paste your custom CSS into the Header field
  5. Wrap the code in a {style} block
  6. Save

Paste the following:

{style}
code {
    padding: 1px 5px 1px 5px; 
    font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
    background-color: #eeeeee;
}
{style}

After that you'll get nice and tidy stackoverflow-stylish inline code spans just by writing {{sometext}}.

查看更多
虎瘦雄心在
5楼-- · 2019-01-29 19:38

Surround your inline text with {{ }}.

Caveats:

  1. You have to hit the spacebar after }}
  2. You can't copy inline preformatted text and maintain it's look. If you do copy it you might not be able to add {{ }} to fix it. Just retype it or paste without formatting (Cmd ⌘+Shift+V on Mac) then add {{ }} and hit space.
  3. If you add the {{ }} to existing text later, it can not be surrounded by other characters, e.g. if you want parenthesis around your preformatted text, you cannot fix (my text) by adding braces ({{my text}}). First add space around your text ( my text ) then add the {{ }}.
查看更多
Ridiculous、
6楼-- · 2019-01-29 19:39

To insert inline monospace font in Confluence, surround the text in double curly-braces.

This is an {{example}}.

If you're using Confluence 4.x or higher, you can also just select the "Preformatted" option from the paragraph style menu.

Full reference here: https://confluence.atlassian.com/display/CONF56/Quick+Reference+Guide+for+the+Confluence+Editor

查看更多
ら.Afraid
7楼-- · 2019-01-29 19:39

All of these other answers certainly sound like good ideas and I would recommend using them first, but I will go ahead and add one more to the list for completeness' sake.

You could simply use the html macro and then paste your content wrapped in <pre> </pre> tags.

查看更多
登录 后发表回答