How to format an inline code in Confluence?

后端 未结 15 530
夕颜
夕颜 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:20

    You could ask your fiendly Confluence administrator to create a macro for you. Here is an example of a macro for Confluence 3.x

    Macro Name:    inlinecode
    Macro Title:   Markup text like stackoverflow inline code
    Categories:    Formatting
    Macro Body Processing: Convert wiki markup to HTML
    Output Format: HTML
    Template:
    
    ## Macro title: Inline Code
    ## Macro has a body: Y
    ## Body processing: Convert wiki markup to HTML
    ## Output: HTML
    ##
    ## Developed by: My Name
    ## Date created: dd/mm/yyyy
    ## Installed by: My Name
    ## This makes the body text look like inline code markup from stackoverflow
    ## @noparams
    <span style="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;">$body</span>
    

    Then users can use {inlinecode}like this{inlinecode}

    You could also use the {html} or {style} macros if they are installed or add this style to the stylesheet for your space.

    While you are at it ask your Confluence admin to create a kbd macro for you. Same as the above, except Macro name is kbd and Template is:

    <span style="padding: 0.1em 0.6em;border: 1px solid #ccc; font-size: 11px; font-family: Arial,Helvetica,sans-serif; background-color: #f7f7f7; color: #333;  -moz-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset; -webkit-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset; box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; display: inline-block; margin: 0 0.1em; text-shadow: 0 1px 0 #fff; line-height: 1.4; white-space: nowrap; ">$body</span> 
    

    Then you can write documentation to tell users to hit the F1 and Enter keys.

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

    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!

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

    If you have WinWord, you can copy what you need into that, touch up the results, and then paste that into Confluence. I've found that easier than the other solutions here.

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

    As of Confluence 4 and above, typing two curly brackets does not work.

    You now need to select Monospace font. Highlight the text you want to change and:

    Windows: Ctrl + Shift + M

    Mac: Command + Shift + M

    Alternatively, you can type a backtick (`) and Confluence will format everything until you type another backtick

    Alternatively, next to the bold and italic options, you can click the "more" drop down and select Monospace:

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

    Easiest way for me is to Insert Markup.

    Then in text box type the text between curly braces.

    It will insert the formatted text in a new line but you can copy it anywhere, even inline.

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

    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.

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