使用 AsciiDoctor,如何在源代码块和示例块中传递变量?

Jea*_* T. 3 asciidoc asciidoctor

有谁知道如何在 Asciidoc 中将变量传递{var}[source]块和示例块(带有====)?

我已经尝试了以下

: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
====
Run Code Online (Sandbox Code Playgroud)

但这就是我得到的:

结果

实际上,第一个“示例”正在运行,但它不是理想的解决方案,因为:

  • 它不像其他示例那样有灰色区域
  • 我需要+在每一行的末尾添加一个

期待您的投入。提前致谢!

Ehm*_*Kah 6

如此处所述您需要在代码块中打开属性替换。你可以用[subs="attributes"]完整的例子来实现它应该是这样的:

[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
====
Run Code Online (Sandbox Code Playgroud)