Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to define own asciidoc macro

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.

In particular, I have the following asciidoc snippet:

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

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?

like image 713
igagis Avatar asked May 19 '16 17:05

igagis


People also ask

How do I create a link in AsciiDoc?

To define a link in Asciidoc markup we only have to type the URL followed by an optional text for the link in square brackets ( [text link] ).

What is AsciiDoc format?

AsciiDoc is a text document format that was explicitly designed with the needs of publishing in mind, both print and web. It supports all the structural elements necessary for writing notes, documentation, articles, books, ebooks, slideshows, web pages, technical manuals and blogs.

How do I view AsciiDoc?

To preview an AsciiDoc document in a web browser, install the Chrome extension, the Edge add-on, the Firefox add-on, or the Opera extension (all produced from the same code base). Then you can see the AsciiDoc file rendered as HTML just by visiting it.

How do you use ADOC?

How to open an ADOC file. You can open an ADOC file and edit the text it contains in any text editor, including Microsoft Notepad (Windows), Apple TextEdit (Mac), Microsoft Visual Studio Code (cross-platform), and GitHub Atom (cross-platform).


1 Answers

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

  • command definition in LaTeX
  • Templates in MediaWiki.

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

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.

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.

like image 184
Jmini Avatar answered Sep 19 '22 05:09

Jmini