asciidoc: Including bold inside Code Fence
Asked Answered
R

2

5

Ho can I include inside an asciidoc code fence? Here is a sample:

[source,js]
----
function doit() {
    *var thing;*        //  local variable
}
----

The idea is that I would like to highlight certain parts of the code block for teaching purposes.

The above sample doesn’t work.

I have read about using something like [subs="macro"], but (a) I can’t get it working in combination with a code fence, and (b) the documentation is a little unclear about the actual details.

Thanks

BTW I am aware of a similar question AsciiDoc add bold text inside a listing block, but there is no reference to code fences. I have tried the solutions, but the don’t work in this context.

Roodepoortmaraisburg answered 15/8, 2016 at 23:28 Comment(0)
N
5

According to AsciiDocs Documentation, below code

[source,java,subs="verbatim,quotes"] 
----
System.out.println("Hello *bold* text"). 
----

will be displayed as

System.out.println("Hello bold text").

So, you need this -

[source,js,subs="verbatim,quotes"]
----
function doit() {

    *_var thing;_* //  local variable
}
----

It will be displayed as

enter image description here

verbatim and quotes subs are helpful.

NOTE:
One thing we need to keep in mind that the code block is already highlighting syntax. If you want different formatting, better not to use code block.

Noncommittal answered 20/12, 2017 at 8:46 Comment(1)
Thanks for your answer. (Sorry for the late response — I missed this earlier). You’re right in that the syntax highlighting may compete with additional formatting, but I can work around that.Roodepoortmaraisburg
H
2

In my opinion the philosophy of Asciidoctor for those use case is to use callouts.

[source,js]
----
function doit() {
    var thing; // <1>
}
----
<1> local variable

The second thing you should consider is to extract your code from a real, controled, unit-tested file. You define some markers in this code file and add an include directive in your adoc file.

Check slides 15-21 in this presentation: Writing documentation with Asciidoctor

Hearthstone answered 16/8, 2016 at 10:38 Comment(1)
I will be using callouts as well, but I particularly want to use bold to highlight changes from a previous example.Roodepoortmaraisburg

© 2022 - 2024 — McMap. All rights reserved.