expand_macro(formatter,
name,
content,
args=None)
| source code
|
Called by the formatter when rendering the parsed wiki text.
.. versionadded:: 0.11
.. versionchanged:: 0.12
added the `args` parameter
:param formatter: the wiki `Formatter` currently processing
the wiki markup
:param name: is the name by which the macro has been called;
remember that via `get_macros`, multiple names could be
associated to this macros. Note that the macro names are
case sensitive.
:param content: is the content of the macro call. When called
using macro syntax (`[[Macro(content)]]`), this is the
string contained between parentheses, usually containing
macro arguments. When called using wiki processor syntax
(`{{{!#Macro ...}}}`), it is the content of the processor
block, that is, the text starting on the line following the
macro name.
:param args: will be a dictionary containing the named
parameters passed when using the Wiki processor syntax.
The named parameters can be specified when calling the macro
using the wiki processor syntax::
{{{#!Macro arg1=value1 arg2="value 2"`
... some content ...
}}}
In this example, `args` will be
`{'arg1': 'value1', 'arg2': 'value 2'}`
and `content` will be `"... some content ..."`.
If no named parameters are given like in::
{{{#!Macro
...
}}}
then `args` will be `{}`. That makes it possible to
differentiate the above situation from a call
made using the macro syntax::
[[Macro(arg1=value1, arg2="value 2", ... some content...)]]
in which case `args` will always be `None`. Here `content`
will be the
`"arg1=value1, arg2="value 2", ... some content..."` string.
If like in this example, `content` is expected to contain
some arguments and named parameters, one can use the
`parse_args` function to conveniently extract them.
|