asciidoc macros
Asked Answered
E

2

11

I use asciidoc for rendering text.

I have difficulties to understand macros. My goal is to have a simple macro processing (like in LaTeX). I would like to write two Macros:

  1. FOO should be replaced by "bar"
  2. MYTEXT(xyz) should be replaced by: "This is my text xyz!"
    (perhaps with a different way to pass the parameter 'xyz')

Example file abc.txt:

text text text
FOO text FOO
text text text
MYTEXT(jajaja)

This should result in

text text text
bar text bar
text text text
This is my text jajaja!

I would expect that the definition of FOO and MYTEXT has to go into the file abc.conf; probabely into the secion [macro].

Additional question:

Are there problems with the pattern matching, if FOO should be replace with 'bar' and FOOX with 'barbar'?

Ear answered 28/1, 2012 at 13:20 Comment(0)
B
6

For the task of substituting FOO into bar and FOOX into barbar I would use the substitution syntax:

= AsciiDoc title
:FOO: bar
:FOOX: barbar

Regular text here using substitutions: {FOO} is bar and {FOOX} is barbar.

As you can see, you declare the substitution as :VARIABLE: and you use it as {VARIABLE}.

As to actually creating new macros, macros are usually of the type macroname:content[Text input]. They are documented here for the Python AsciiDoc project and eventually here for the ruby based AsciiDoctor project but I have never really used them, I prefer substitutions and conditional blocks.

Bespectacled answered 1/11, 2013 at 18:44 Comment(1)
You provide an alternate solution, but you don't actually answer the question.Vat
F
0

There is a separate project, that I am associated with

http://github.com/verhas/jamal

which is a macroprocessor and it is available as an Asciidoctor preprocessor. Note that this is not Asciidoc, which is the format, but the implementation of the converter, Asciidoctor.

I think that Jamal just does exactly what you are looking for. It has complex macro processing capabilities that superseed those of Asciidoc and there are also a lot of built-in macros, some replacing, some extending the Asciidoc formatting and macro capabilities.

Fortunna answered 25/4, 2022 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.