如何在Confluence中这样格式化内联代码?我的意思是,不是一个单独的代码块,而只是内联类名。


当前回答

我发现用颜色格式化有点棘手,因为Confluence(5.6.3)对{{monospace}}块周围的空格非常挑剔。

其他回答

我发现做到这一点的最简单的方法是从行开始写markdown。按Ctrl+D(打开标记输入对话框的快捷键)并键入markdown。普通的维基编辑器似乎不太适合精确格式化。它似乎不太了解字符样式,只知道段落样式。

用{{}}包围内联文本。

警告:

You have to hit the spacebar after }} 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. 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 {{ }}.

若要在文本内格式化代码,请使用' "字符将代码括起来。通常位于键盘上“1”键的左边。

例子:

`printf("Hello World");`

与Stack Exchange相同的分隔符!

默认情况下,Confluence呈现透明背景的等宽文本。您可以编辑全局CSS添加灰色。来自Confluence手册:

选择屏幕右上角的齿轮图标,然后选择Confluence Admin。 选择样式表。 选择编辑。 将自定义CSS粘贴到文本字段中。 选择保存。

自定义CSS显示灰色背景在等宽块:

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

如果您正在使用Confluence OnDemand(云):

点击左边侧边栏底部的齿轮 选择外观和感觉 单击边栏、页眉和页脚选项卡 将自定义CSS粘贴到Header字段中 将代码包装在一个{style}块中 保存

粘贴如下内容:

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

在此之后,只需编写{{sometext}},就可以得到漂亮整洁的堆栈溢出风格的内联代码跨度。

汇合之后

对于合流4及以上版本,输入两个花括号不起作用。

你现在需要选择Monospace字体。突出显示要更改的文本,并:

Windows操作系统:Ctrl + Shift + M

Mac: Command + Shift + M

或者,您可以键入一个反撇号('),Confluence将格式化所有内容,直到您键入另一个反撇号

或者,在粗体和斜体选项旁边,你可以点击“更多”下拉菜单,选择Monospace: