Add more WikiCreole syntaxes for text styles
authorBernardo Innocenti <bernie@codewiz.org>
Mon, 17 Dec 2007 10:20:44 +0000 (11:20 +0100)
committerBernardo Innocenti <bernie@codewiz.org>
Mon, 17 Dec 2007 10:20:44 +0000 (11:20 +0100)
geekigeeki.py

index 7193d5520b50af8bb709453f3cb53f721d9c7efd..43b9cc1107ac68b484b205b86e69f79d18107b25 100755 (executable)
@@ -336,22 +336,27 @@ class PageFormatter:
     def __init__(self, raw):
         self.raw = raw
         self.h_level = 0
-        self.in_pre = self.in_table = self.in_tt = self.in_em = self.in_b = False
+        self.in_pre = self.in_table = False
         self.in_header = True
         self.list_indents = []
         self.tr_cnt = self.h_cnt = 0
+        self.styles = {
+            #wiki   html   enabled?
+            "//":  ["em",  False],
+            "''":  ["em",  False],
+            "**":  ["b",   False],
+            "'''": ["b",   False],
+            "##":  ["tt",  False],
+            "``":  ["tt",  False],
+            "__":  ["u",   False],
+            "^^":  ["sup", False],
+            ",,":  ["sub", False]
+        }
 
     def _b_repl(self, word):
-        self.in_b = not self.in_b
-        return ['</strong>', '<strong>'][self.in_b]
-
-    def _em_repl(self, word):
-        self.in_em = not self.in_em
-        return ['</em>', '<em>'][self.in_em]
-
-    def _tt_repl(self, word):
-        self.in_tt = not self.in_tt
-        return ['</tt>', '<tt>'][self.in_tt]
+        style = self.styles[word]
+        style[1] = not style[1]
+        return ['</','<'][style[1]] + style[0] + '>'
 
     def _tit_repl(self, word):
         if self.h_level:
@@ -495,9 +500,7 @@ class PageFormatter:
         scan_re = re.compile(
             r"(?:"
             # Formatting
-            + r"(?P<b>\*\*|''')"
-            + r"|(?P<em>//|'')"
-            + r"|(?P<tt>##|``)"
+            + r"(?P<b>\*\*|'''|//|''|##|``|__|\^\^|,,)"
             + r"|(?P<tit>\={2,6})"
             + r"|(?P<br>\\\\)"
             + r"|(?P<rule>^-{3,})"