|
CreoleMacros
How to use macros in creole2html converter
Featured IntroductionThe 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) DetailsA 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.) Examplefrom 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> | |
► Sign in to add a comment