codekasten/wortschlucker/src/tools.py
lars 5355c8a34b added code for converting creole to html
* fixed the new line markup (\\) of creole
2010-04-26 01:43:11 +00:00

14 lines
654 B
Python

from creoleparser import text2html
"""
text can be creole-encoded, see http://www.wikicreole.org/imageServlet?page=CheatSheet%2Fcreole_cheat_sheet.png&width=340
"""
def creole2html(text):
# creoleparser returns an utf-8 encoded string by default, but this would cause "Markup" below to fail during decoding.
# The parameter "None" for "encoding" forces unicode output. This works with "Markup".
# Replace single backslashes with double ones (new line for creole), since python
# interprets a double backslash as the escape sequenze of a single backslash.
text = text.replace("\\", "\\\\")
return text2html(text, encoding=None)