Make syntax a lot closer to Creole1.0
authorBernardo Innocenti <bernie@codewiz.org>
Sat, 29 Sep 2007 20:11:47 +0000 (22:11 +0200)
committerBernardo Innocenti <bernie@codewiz.org>
Sat, 29 Sep 2007 20:11:47 +0000 (22:11 +0200)
geekigeeki.css
geekigeeki.py

index cded557a63db165c77e1689507b006af76651b21..c0e640df1339c59bd4a9ca31762f9709743d8434 100755 (executable)
@@ -233,11 +233,12 @@ table {
        margin-bottom: 0.5em;
 }
 
-table thead {
+table tbody thead {
        background: #f7f7f0
 }
 
-table thead th {
+/* FIXME: should be thead */
+table tbody th {
        border: 1px solid #d7d7d7;
        border-bottom-color: #999;
        font-weight: bold;
index abaa4338ee109158cc2fd4f90009423fe990e4f2..12b6b7cdaec57d05e14baadd381c17a6431029bb 100755 (executable)
@@ -129,7 +129,7 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'):
     print '<div class="nav">'
     print '  <b>' + site_name + ': ',
     if name:
-        print link_tag('?fullsearch=' + name, text) + '</b> '
+        print link_tag('?fullsearch=' + name, text, 'navlink') + '</b> '
     else:
         print text + '</b> '
     print ' | ' + link_tag('FrontPage', 'Front Page', 'navlink')
@@ -334,23 +334,19 @@ class PageFormatter:
     """
     def __init__(self, raw):
         self.raw = raw
-        self.is_em = self.is_b = 0
         self.h_level = 0
-        self.h_count = 0
-        self.list_indents = []
-        self.in_pre = False
-        self.in_table = False
-        self.tr_cnt = 0
-        self.in_var = False
+        self.in_pre = self.in_table = self.in_var = self.in_em = self.in_b = False
         self.in_header = True
+        self.list_indents = []
+        self.tr_cnt = self.h_cnt = 0
 
-    def _emph_repl(self, word):
-        if len(word) == 3:
-            self.is_b = not self.is_b
-            return ['</strong>', '<strong>'][self.is_b]
-        else:
-            self.is_em = not self.is_em
-            return ['</em>', '<em>'][self.is_em]
+    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 _tit_repl(self, word):
         if self.h_level:
@@ -358,10 +354,13 @@ class PageFormatter:
             self.h_level = 0
         else:
             self.h_level = len(word) - 1
-            self.h_count += 1
-            result = '<h%d id="%d"><a class="heading" href="#%d">*</a> ' % (self.h_level, self.h_count, self.h_count)
+            self.h_cnt += 1
+            result = '<h%d id="%d"><a class="heading" href="#%d">*</a> ' % (self.h_level, self.h_cnt, self.h_cnt)
         return result
 
+    def _br_repl(self, word):
+        return '<br />'
+
     def _rule_repl(self, word):
         return self._undent() + '\n<hr size="%d" noshade="noshade" />\n' % (len(word) - 2)
 
@@ -379,9 +378,9 @@ class PageFormatter:
             return '<a href="%s" rel="nofollow" class="external">%s</a>' % (word, word)
 
     def _hurl_repl(self, word):
-        m = re.compile("\[\[(\S+)([^\]]*)\]\]").match(word)
+        m = re.compile("\[\[(\S+)(?:\s*\|\s*([^\]]*)|)\]\]").match(word)
         name = m.group(1)
-        descr = m.group(2).strip() or name
+        descr = m.group(2) or name
 
         macro = globals().get('_macro_' + name)
         if macro:
@@ -393,7 +392,7 @@ class PageFormatter:
         elif name.startswith('/'):
             return '<a href="%s">%s</a>' % (name, descr)
         else:
-            return link_tag(name, descr)
+            return link_tag(name, descr, 'wikilink')
 
     def _email_repl(self, word):
         return '<a href="mailto:%s">%s</a>' % (word, word)
@@ -443,16 +442,17 @@ class PageFormatter:
             self.tr_cnt = 0
             out = '</p><table><tbody>\n'
         self.tr_cnt += 1
-        return out + '<tr class="' + ['even', 'odd'][self.tr_cnt % 2] + '"><td>'
+        out = out + '<tr class="' + ['even', 'odd'][self.tr_cnt % 2] + '">'
+        return out + ['<td>', '<th>'][word.strip() == '||=']
 
-    def _tre_repl(self, word):
+    def _td_repl(self, word):
         if self.in_table:
-            return '</td></tr>'
+            return ['</td><td>', '</th><th>'][word.strip() == '||=']
         return ''
 
-    def _td_repl(self, word):
+    def _tre_repl(self, word):
         if self.in_table:
-            return '</td><td>'
+            return ['</td></tr>', '</th></tr>'][word.strip() == '||=']
         return ''
 
     def _indent_level(self):
@@ -494,8 +494,10 @@ class PageFormatter:
         scan_re = re.compile(
             r"(?:"
             # Formatting
-            + r"(?P<emph>'{2,3})"
+            + r"(?P<b>\*\*|''')"
+            + r"|(?P<em>//|'')"
             + r"|(?P<tit>\={2,6})"
+            + r"|(?P<br>\\\\)"
             + r"|(?P<rule>^-{3,})"
             + r"|(?P<html><(/|)(div|span|iframe)[^<>]*>)"
             + r"|(?P<ent>[<>&])"
@@ -504,19 +506,19 @@ class PageFormatter:
             # Links
             + r"|(?P<img>\b[a-zA-Z0-9_-]+\.(png|gif|jpg|jpeg|bmp))"
             + r"|(?P<word>\b(?:[A-Z][a-z]+){2,}\b)"
-            + r"|(?P<hurl>\[\[\S+[^\]]*\]\])"
+            + r"|(?P<hurl>\[\[(\S+)(?:\s*\|\s*([^\]]*)|)\]\])"
             + r"|(?P<url>(http|https|ftp|mailto)\:[^\s'\"]+\S)"
             + r"|(?P<email>[-\w._+]+\@[\w.-]+)"
 
             # Lists, divs, spans
-            + r"|(?P<li>^\s+\*)"
-            + r"|(?P<pre>(\{\{\{|\s*\}\}\}))"
-            + r"|(?P<var>(\{\{|\}\}))"
+            + r"|(?P<li>^\s+[\*#] +)"
+            + r"|(?P<pre>\{\{\{|\s*\}\}\})"
+            + r"|(?P<var>\{\{|\}\})"
 
             # Tables
-            + r"|(?P<tr>^\s*\|\|\s*)"
-            + r"|(?P<tre>\s*\|\|\s*$)"
-            + r"|(?P<td>\s*\|\|\s*)"
+            + r"|(?P<tr>^\s*\|\|(=|)\s*)"
+            + r"|(?P<tre>\s*\|\|(=|)\s*$)"
+            + r"|(?P<td>\s*\|\|(=|)\s*)"
             + r")")
         pre_re = re.compile(
             r"(?:"