问题
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?
回答1:
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 substitutionsnormal
- Performs all substitutions except for calloutsverbatim
- Replaces special characters and processes calloutsspecialchars / specialcharacters
- Replaces <, >, and & with their corresponding entitiesquotes
- Applies text formattingattributes
- Replaces attribute referencesreplacements
- Substitutes textual and character reference replacementsmacros
- Processes macrospost_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.
回答2:
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
----
来源:https://stackoverflow.com/questions/29124154/substitutions-inside-literals-in-asciidoc