2

I am using asciidoc to generate course materials as PDF. When the materials are printed, I do not want the code samples to be highlighted, because they do not print well. When the materials are read with a PDF reader, I do want highlighting.

I have defined a variable highlight, and I can do the following, which works fine:

ifdef::highlight[]
[source, {language}]
endif::highlight[]
----
code
----

I have dozens of code examples in dozens of chapters, so I'd like to use a macro that can check the status of the highlight variable and conditionally include the source macro. Then I can generate the print-friendly version by default, but define the highlight version on the command line when I need the viewer-friendly version.

I have written such a macro (in my asciidoc config file):

[macros] 
(?u)^(?P<name>hlsource)::(?P<target>\S*?)(\[(?P<attrlist>.*?)\])$=# 

[hlsource-blockmacro] 
ifdef::highlight[]
[source, {language}] 
endif::highlight[]  

The problem is that it literally includes the text "[source, python]" in my generated PDF file rather than being interpreted as an asciidoc directive.

Note: language is a variable set in the config file.

Can anyone confirm whether such nested macros are even possible in asciidoc, and if so, how to do it.

Thanks!

0 Answers0