From 5355c8a34bb992791d3389e4feb7f8db3563c171 Mon Sep 17 00:00:00 2001 From: lars Date: Mon, 26 Apr 2010 01:43:11 +0000 Subject: [PATCH] added code for converting creole to html * fixed the new line markup (\\) of creole --- wortschlucker/src/tools.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 wortschlucker/src/tools.py diff --git a/wortschlucker/src/tools.py b/wortschlucker/src/tools.py new file mode 100644 index 0000000..972a504 --- /dev/null +++ b/wortschlucker/src/tools.py @@ -0,0 +1,14 @@ +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) +