Substitutions inside literals in Asciidoc
Asked Answered
H

2

7

There doesn't appear to be a way to have variables (attributes, substitutions) parsed within literal text in Asciidoc, or else I'm missing something. I want to be able to set a variable and then call it inside a code block or literal string as such:

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

And have it parse to:

tar -xzvf mysoftware-1.0.1.tar.gz

This can't be impossible, right?

Hardheaded answered 18/3, 2015 at 14:2 Comment(0)
P
8

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

  • none - Disables substitutions
  • normal - Performs all substitutions except for callouts
  • verbatim - Replaces special characters and processes callouts
  • specialchars / specialcharacters - Replaces <, >, and & with their corresponding entities
  • quotes - Applies text formatting
  • attributes - Replaces attribute references
  • replacements - Substitutes textual and character reference replacements
  • macros - Processes macros
  • post_replacements - Replaces the line break character (+)

More info can be found in the User Manual, including an example very close to what you're trying to accomplish.

Pamela answered 19/3, 2015 at 15:54 Comment(0)
M
6

Substitutions inside listing blocks are off by default, but can be controlled with the subs parameter:

:version: 1.0.1
[code, subs="attributes"]
----
tar -xzvf mysoftware-{version}.tar.gz
----
Muggy answered 11/5, 2015 at 12:27 Comment(1)
LightGuard's answer is more complete, but I think it's useful to see how it applies to the example from the question.Muggy

© 2022 - 2024 — McMap. All rights reserved.