如何定义自己的asciidoc宏 [英] how to define own asciidoc macro

查看:123
本文介绍了如何定义自己的asciidoc宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asciidoc / asciidoctor中定义宏?

How do I define a macro in asciidoc/asciidoctor?

我将在文档的许多部分中使用重复模式,因此我想进行参数化替换为了避免多次输入相同的内容。

I will use a repeating pattern in many parts of my document so I would like to make a parametrized substitution to avoid entering the same stuff many times.

特别是,我有以下asciidoc代码段:

In particular, I have the following asciidoc snippet:

{set:cellbgcolor:grey}
[grid=none, frame=none]
|===
| X >| Y
|===
{set:cellbgcolor!}

需要将其放置在文档的不同部分中,用不同的文本替换代替X和Y。

And I need to place it in several parts of the document with different text substitutions in place of X and Y. How do I achieve that?

推荐答案

我认为您无法通过Asciidoctor获得其他文档引擎中的所有灵活性/简单性:

In my opinion you do not get with Asciidoctor all the flexibility/simplicity you get in other documentation engines:


  • LaTeX中的命令定义

  • 模板在MediaWiki中。

  • command definition in LaTeX
  • Templates in MediaWiki.

我认为您可以使用Asciidoctor中的include宏和变量:

I think that you can work with the include macro and variables in Asciidoctor:

创建一个名为 snippet.adoc 的文件(我的示例基于您的示例):

Create a file called snippet.adoc (my example is based on your example):

{set:cellbgcolor:grey}
[grid=none, frame=none]
|===
| {paramX} >| {paramY}
|===
{set:cellbgcolor!}

在您的主文档中使用它是这样的:

In your main document use it like this:

== My document

:paramX: lorem
:paramY: ipsum
include::snippet.adoc[]

Lorem ipsum dolore.

:paramX: aaaa
:paramY: bbbb
include::snippet.adoc[]

Lorem ipsum dolore.






说asciidoctor可以扩展。您也可以创建自己的真实宏(用Java或Ruby编写),但这需要更多工作。根据您的用例,您可以在线找到几个示例。


That said asciidoctor can be extended. You can also create your own real macro (written in Java or in Ruby), but this requires more work. Depending on your use case, you can find several examples online.

这篇关于如何定义自己的asciidoc宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆