Substitutions inside literals in Asciidoc

There seems to be no way for variables (attributes, substitutions) to be parsed in literal text in Asciidoc, otherwise I'm missing something. I want to be able to set a variable and then call it inside a block of code or a literal string as such:

:version: 1.0.1 [code] ---- tar -xzvf mysoftware-{version}.tar.gz ---- 

And analyze it:

 tar -xzvf mysoftware-1.0.1.tar.gz 

It can't be impossible, right?

+4
asciidoc
source share
2 answers

You can enable it for any block using the subs attribute for the block. The subs attribute accepts any of the following (in the list):

  • none - disables lookups
  • normal - performs all replacements except callouts
  • verbatim - Replaces special characters and process calls
  • specialchars / specialcharacters - Replaces <,> and with corresponding objects
  • quotes - Applies text formatting
  • attributes - Replaces attributes references
  • replacements - replaces text and symbolic links.
  • macros - handles macros
  • post_replacements - Replaces the line break character (+)

More information can be found in the user manual , including an example very close to what you are trying to accomplish.

+5
source share

Replacements inside listing blocks are disabled by default, but they can be controlled using the subs parameter:

 :version: 1.0.1 [code, subs="attributes"] ---- tar -xzvf mysoftware-{version}.tar.gz ---- 
+3
source share

All Articles