How to format an inline code in Confluence?

后端 未结 15 531
夕颜
夕颜 2020-12-22 17:57

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

相关标签:
15条回答
  • 2020-12-22 18:29

    In Confluence 5.4.2 you can add surround your inline code with <code></code> tags in the source editor thusly:

    Confluence will show <code>this inline code</code> in a fixed font. 
    

    This can be useful where there are many fragments to modify since the double-brace feature only works when adding text interactively in the Confluence editor.

    0 讨论(0)
  • 2020-12-22 18:33

    The easiest way I've found to do this is to write in markdown right from the start of the line. Press Ctrl+D (shortcut for opening the markup input dialog) and type markdown. The normal wiki editor doesn't seem to be very good for precise formatting. It doesn't seem to know much about character styles and only knows paragraph styles.

    0 讨论(0)
  • 2020-12-22 18:35

    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. Please note that will apply to the entire line.

    Full reference here.

    0 讨论(0)
  • 2020-12-22 18:37

    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 {{ }}.
    0 讨论(0)
  • 2020-12-22 18:38

    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

    0 讨论(0)
  • 2020-12-22 18:43

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

    0 讨论(0)
提交回复
热议问题