-
Notifications
You must be signed in to change notification settings - Fork 13
Creole Macros
JensDiemer edited this page Apr 5, 2015
·
1 revision
The creole2html converter supports macros. No macros are activated by default.
We shipped a example file with python-creole, located in /creole/shared/example_macros.py (See also unittests macros: /creole/tests/test_macros.py)
A macro can get arguments and a text block. The macro function must return a unicode string back which replaced the code block.
You must pass a dict or a object with callable attributes to creole2html or HtmlEmitter. (See the sourcecode of /creole/creole2html/emitter.py and his macro_emit() method.)
from creole import creole2html
def example_macro(char, text):
""" very simple macro """
return char.join(text.split())
source_creole = """\
Here a example usage:
<<example_macro char="|">>
a
b
c
<</example_macro>>
That's it."""
html = creole2html(source_creole,
macros={"example_macro": example_macro}
)
print(html)
The output will be:
<p>Here a example usage:</p>
a|b|c
<p>That's it.</p>