Jean-Francois T.
Jean-Francois T.

Reputation: 12930

With AsciiDoctor, how to pass variables in source and example blocks?

Any one knows how to pass variables {var} into [source] blocks and example blocks (with ====) in Asciidoc?

I have tried the following

:country: France
:city: Shanghai

[source]
----
print("{country} is a country")
print("{city} is a city")
----

.Example
====
{country} is a country +
{city} is a city
====

.Example with better alignment
====
    {country} is a country
    {city} is a city
====

But this is what I get:

result

Actually the first "example" is working but it is not the ideal solution because:

Looking forward your inputs. Thanks in advance!

Upvotes: 9

Views: 5389

Answers (1)

As described here you need to switch on attribute replacement in code blocks. You can achieve it with [subs="attributes"]complete example should look something like:

[source, subs="attributes"]
----
  print("{country} is a country")
  print("{city} is a city")
----

.Example with better alignment
====
[subs="attributes"]
    {country} is a country
    {city} is a city
====

Upvotes: 11

Related Questions