Create a Table with Highlighted Source Code in Asciidoc

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.

1 Answer

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:

docs can be found here:

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

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest