Helpers and filters for Creole usage in Flask.
Install:
easy_install Flask-Creole
Code:
hg clone http://bitbucket.org/aafshar/flask-creole-main
Load the extension:
from flaskext.creole import Creole
creole = Creole(app)
Now in your templates you can use the filters:
{{ article.body|creole2html }}
You can also use this functionality outside templates:
from flaskext.creole import Creole
creole = Creole(app)
article.html = creole.creole2html(article.body)
You can add your own macros to extend creoleparser.
Load the extension and declare the macro:
from flaskext.creole import Creole
creole = Creole(app)
@creole.macro
def hello(name, environ, body, is_block, *args, **kw):
return 'Hello World'
Now use it in some markup:
{{ '<<hello>>'|creole2html }}
Flask extension to add template filters for using creole
Parameters: |
|
---|
Add a named macro to the macros.
Parameters: |
|
---|
Convert creole markup to html
Parameters: |
|
---|
Dispatch a macro.
Called internally, usually.
Decorator to define a function as a creole macro.
The function should take the signature:
def macro_function(name, environ, body, is_block, *args, **kw):
...
Where *args and **kw can be replaced by specific macro argument names, or omitted entirely if the macro has no arguments.
This decorator may be called with a name to use for the macro, and if omitted the decorated function name will be used instead.
All the following are acceptable:
creole = Creole(app)
@creole.macro
def macro_function(name, environ, body, is_block, *args, **kw):
...
@creole.macro('my_macro_name')
def macro_function(name, environ, body, is_block, *args, **kw):
...
@creole.macro()
def macro_function(name, environ, body, is_block, *args, **kw):
...