Allow expanding wiki syntax within html tags
authorBernie Innocenti <bernie@codewiz.org>
Wed, 8 Apr 2009 19:40:47 +0000 (21:40 +0200)
committerBernie Innocenti <bernie@codewiz.org>
Wed, 8 Apr 2009 19:40:47 +0000 (21:40 +0200)
geekigeeki.py

index 106250b10c63a627109a333dc7ffbfa9b85bea60..4450aead0d3617848117f6c7ad6098a758b8877d 100755 (executable)
@@ -37,12 +37,17 @@ link_re = re.compile("(?:\[\[|{{)([^\s\|]+)(?:\s*\|\s*([^\]]+)|)(?:\]\]|}})")
 
 title_done = False
 
-
 # CGI stuff ---------------------------------------------------------
-
 def script_name():
     return os.environ.get('SCRIPT_NAME', '')
 
+def query_string():
+    path_info = os.environ.get('PATH_INFO', '')
+    if len(path_info) and path_info[0] == '/':
+        return path_info[1:] or 'FrontPage'
+    else:
+        return os.environ.get('QUERY_STRING', '') or 'FrontPage'
+
 def privileged_path():
     return privileged_url or script_name()
 
@@ -365,7 +370,10 @@ class WikiFormatter:
         if macro:
             return macro(argv)
         else:
-            return '<strong class="error">&lt;&lt;' + '|'.join(argv) + '&gt;&gt;</strong>'
+            msg = '&lt;&lt;' + '|'.join(argv) + '&gt;&gt;'
+            if not self.in_html:
+                msg = '<strong class="error">' + msg + '</strong>'
+            return msg
 
     def _hurl_repl(self, word):
         m = link_re.match(word)
@@ -407,10 +415,13 @@ class WikiFormatter:
         self.in_html += 1
         return word; # Pass through
 
+    def _htmle_repl(self, word):
+        self.in_html -= 1
+        return word; # Pass through
+
     def _ent_repl(self, s):
-        if self.in_html and s == '>':
-            self.in_html -= 1
-            return '>'
+        if self.in_html:
+            return s; # Pass through
         return {'&': '&amp;',
                 '<': '&lt;',
                 '>': '&gt;'}[s]
@@ -496,15 +507,16 @@ class WikiFormatter:
             | (?P<tit>   \={2,6})
             | (?P<br>    \\\\)
             | (?P<rule>  ^-{3,})
-            | (?P<hi>    \b(FIXME|TODO|DONE)\b)
+            | (?P<hi>    \b( FIXME | TODO | DONE )\b )
 
             # Links
             | (?P<macro> \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)
             | (?P<hurl>  \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])
 
             # Inline HTML
-            | (?P<html>  <(/|)(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])[^>]*>)
-            | (?P<ent>   [<>&])
+            | (?P<html>  <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
+            | (?P<htmle> ( /\s*> | </(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])> ) )
+            | (?P<ent>   [<>&] )
 
             # Auto links (LEGACY)
             | (?P<img>   \b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt))
@@ -786,12 +798,7 @@ def main():
             handler(form[cmd].value)
             break
     else:
-        path_info = os.environ.get('PATH_INFO', '')
-        if len(path_info) and path_info[0] == '/':
-            query = path_info[1:] or 'FrontPage'
-        else:
-            query = os.environ.get('QUERY_STRING', '') or 'FrontPage'
-
+        query = query_string()
         if file_re.match(query):
             if word_re.match(query):
                 Page(query).format()