在 Asciidoc 中创建一个突出显示源代码的表

You*_*sen 5 ascii ascii-art asciidoc asciidoctor

我想在表格中突出显示我的一些代码。我尝试了很多方法但我可以解决它。

如果有人能帮助我,我将不胜感激。

rdm*_*ler 8

好问题!

大多数 AsciiDoc 语法不在表格内呈现,仅呈现基本语法,例如*bold*. 您必须明确告诉 Asciidoctor 渲染整个功能集。

有两种方法可以做到这一点:

1) 将字符添加a|您希望 Asciidoctor 呈现完整语法的单元格的前面

2) 通过在表格前面说明您的愿望,将整列配置为呈现为 AsciiDoc:[cols="a,a"]将在两列表格的两列中呈现 AsciiDoc。

这是演示这一点的要点: https://gist.github.com/rdmueller/b79f4b00890f75644a0186c4adda589a

文档可以在这里找到:https ://asciidoctor.org/docs/user-manual/#cols-format

例子:

|====
|Col1 | Col2
| even complex formattings like source code highlighting works this way
a|
[source, groovy]
----
5.times {
    println it
}
----
|====
Run Code Online (Sandbox Code Playgroud)
[cols="a,a"]
|====
|Col1 | Col2
| even complex formattings like source code highlighting works this way
|
[source, groovy]
----
5.times {
    println it
}
----
|====
Run Code Online (Sandbox Code Playgroud)

请参阅这些示例的渲染要点