My favorites | Sign in
Project Home Wiki Issues Source
Search
for

general:

html2creole:

creole2html:

For python-creole developer:

CreoleMacros  
How to use macros in creole2html converter
Featured
Updated Sep 3, 2012 by google-c...@jensdiemer.de

Introduction

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)

Details

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.)

Example

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>

Sign in to add a comment
Powered by Google Project Hosting