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

5
任何人都知道如何将变量 {var} 传递到 Asciidoc 中的 [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
====

但这就是我得到的:

result

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

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

期待您的输入。提前感谢!

1个回答

9

正如这里所描述的,您需要在代码块中打开属性替换功能。您可以使用[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
====

太棒了!请注意,您可以使用[source,subs =“attributes”]来简化...但是仍然有一个问题,即使用=====的“更好对齐示例”的问题:有任何想法吗? - Jean-Francois T.
1

只需在 = 下方添加 [subs="attributes"]。(在注释中很难阅读) 示例更好的对齐方式:

[subs="attributes"] {country} 是一个国家 {city} 是一个城市

或者我理解有误吗?(更新的答案)
- EhmKah a.k.a. Michael Krauße

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接