Create a Table with highlighted Source Code in Asciidoc
Asked Answered
F

1

7

I would like to highlight some of my code in tables. I tried many ways but I could get it fixed.

I would appreciate if someone can help me.

Fundus answered 3/4, 2019 at 6:24 Comment(0)
R
10

great question!

Most AsciiDoc syntax is not rendered inside a table, only basic syntax like *bold*. You have to explicitly tell Asciidoctor to render the whole feature set.

There are two ways to do so:

1) prepend the character a to the | of the cell where you want Asciidoctor to render the full syntax

2) configure a whole column to be rendered as AsciiDoc by stating your wish in front of the table: [cols="a,a"] will render a AsciiDoc in both columns of a two column table.

here is a gist to demonstrate this: https://gist.github.com/rdmueller/b79f4b00890f75644a0186c4adda589a

docs can be found here: https://asciidoctor.org/docs/user-manual/#cols-format

Examples:

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

See the gist for a rendering of these examples

Rahal answered 3/4, 2019 at 6:39 Comment(3)
Could you give me maybe an example?Fundus
do these examples fit?Rahal
For future answer seekers: I'd also add [%autowidth, cols="a,a"] for width as mentionded here: https://mcmap.net/q/1480968/-auto-width-columns-or-tex-like-tabular-in-asciidocJellify

© 2022 - 2024 — McMap. All rights reserved.