Add wiki tables
authorBernardo Innocenti <bernie@codewiz.org>
Fri, 14 Sep 2007 08:54:11 +0000 (10:54 +0200)
committerBernardo Innocenti <bernie@trinity.develer.com>
Fri, 14 Sep 2007 08:56:03 +0000 (10:56 +0200)
geekigeeki.css
geekigeeki.py

index e1eb871731074323460ac7929a1f30818b6b7f5d..49062cd551509042016bf19db8c52b30b8b0066e 100755 (executable)
@@ -120,11 +120,17 @@ h5 {
        padding-left: 5px;
 }
 
+strong.hilight {
+       padding-left: 0.1em;
+       background-color: #ee2222;
+}
+
 div {
        margin-left: 10px;
        margin-right: 10px;
        text-align: justify;
 }
+
 div.wiki {
        margin-left: 0;
        margin-right: 0;
@@ -215,17 +221,42 @@ p {
        text-align: justify;
 }
        
-caption {
-       background-color: #4682B4;
-       color: #FFFFFF;
+table {
+       /*width: 100%;*/
+       border: 2px solid #ccc;
+       border-collapse: collapse;
+       margin-left: 1em;
+       margin-right: 1em;
+       margin-top: 0.5em;
+       margin-bottom: 0.5em;
+}
+
+table thead {
+       background: #f7f7f0
+}
+
+table thead th {
+       border: 1px solid #d7d7d7;
+       border-bottom-color: #999;
        font-weight: bold;
-       border: #000000;
-       border-top-width: 1px;
-       border-right-width: 1px;
-       border-bottom-width: 0px;
-       border-left-width: 1px;
-       border-style: solid;
-}      
+       padding: 2px .5em;
+       vertical-align: bottom;
+}
+
+table tbody td {
+       border: 1px dotted #ddd;
+       padding: .3em .5em;
+       vertical-align: top;
+}
+
+table tbody tr { border-top: 1px solid #ddd }
+table tbody tr.even { background-color: #f0f0f0 }
+table tbody tr.odd { background-color: #e7e7e7 }
+table tbody tr:hover { background: #eed !important }
+
+table thead th :link:hover, table thead th :visited:hover table tbody td a:hover, table tbody th a:hover {
+       background-color: transparent;
+}
 
 pre {
        color: #222222;
index 116b03b480911485162d8c6bacc49b3cddd1f523..aa6d332a449e2b9b3ce481e38c0862f820ce67af 100755 (executable)
@@ -107,7 +107,7 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'):
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 """
     print "<head><title>%s: %s</title>" % (site_name, text)
-    print ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
+    print ' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />'
     if not name:
         print ' <meta name="robots" content="noindex,nofollow" />'
     if css_url:
@@ -338,14 +338,16 @@ class PageFormatter:
         self.is_em = self.is_b = 0
         self.h_level = 0
         self.list_indents = []
-        self.in_pre = 0
-        self.in_var = 0
+        self.in_pre = False
+        self.in_table = False
+        self.tr_cnt = 0
+        self.in_var = False
         self.in_header = True
 
     def _emph_repl(self, word):
         if len(word) == 3:
             self.is_b = not self.is_b
-            return ['</b>', '<b>'][self.is_b]
+            return ['</strong>', '<strong>'][self.is_b]
         else:
             self.is_em = not self.is_em
             return ['</em>', '<em>'][self.is_em]
@@ -408,23 +410,44 @@ class PageFormatter:
 
     def _pre_repl(self, word):
         if word == '{{{' and not self.in_pre:
-            self.in_pre = 1
+            self.in_pre = True
             return '<pre>'
         elif self.in_pre:
-            self.in_pre = 0
+            self.in_pre = False
             return '</pre>'
-        else:
-            return ''
+        return ''
+
+    def _hilight_repl(self, word):
+        return '<strong class="hilight">' + word + '</strong>'
 
     def _var_repl(self, word):
         if word == '{{' and not self.in_var:
-            self.in_var = 1
+            self.in_var = True
             return '<code>'
         elif self.in_var:
-            self.in_var = 0
+            self.in_var = False
             return '</code>'
-        else:
-            return ''
+        return ''
+
+    def _tr_repl(self, word):
+        out = ''
+        if not self.in_table:
+            self.in_table = True
+            self.tr_cnt = 0
+            out = '</p><table><tbody>\n'
+        self.tr_cnt += 1
+        return out + '<tr class="' + ['even', 'odd'][self.tr_cnt % 2] + '"><td>'
+
+    def _tre_repl(self, word):
+        if self.in_table:
+            return '</td></tr>'
+        return ''
+
+    def _td_repl(self, word):
+        if self.in_table:
+            return '</td><td>'
+        return ''
+
     def _macro_repl(self, word):
         macro_name = word[2:-2]
         # TODO: Somehow get the default value into the search field
@@ -465,29 +488,44 @@ class PageFormatter:
 
         # For each line, we scan through looking for magic
         # strings, outputting verbatim any intervening text
+        # TODO: highlight search words (look at referer)
         scan_re = re.compile(
             r"(?:"
+            # Formatting
             + r"(?P<emph>'{2,3})"
             + r"|(?P<tit>\={2,6})"
+            + r"|(?P<rule>^-{3,})"
             + r"|(?P<ent>[<>&])"
+            + r"|(?P<hilight>\b(FIXME|TODO)\b)"
+
+            # 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<rule>^-{3,})"
             + r"|(?P<hurl>\[\[\S+\s+.+\]\])"
             + r"|(?P<url>(http|ftp|nntp|news|mailto)\:[^\s'\"]+\S)"
             + r"|(?P<email>[-\w._+]+\@[\w.-]+)"
+
+            # Lists, divs, spans
             + 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*)"
+
+            # Macros
             + r"|(?P<macro>\[\[(TitleSearch|FullSearch|WordIndex|TitleIndex)\]\])"
             + r")")
         pre_re = re.compile(
             r"(?:"
             + r"(?P<pre>\s*\}\}\})"
             + r")")
-        blank_re = re.compile("^\s*$")
-        indent_re = re.compile("^\s*")
-        eol_re = re.compile(r'\r?\n')
+        blank_re = re.compile(r"^\s*$")
+        indent_re = re.compile(r"^\s*")
+        tr_re = re.compile(r"^\s*\|\|")
+        eol_re = re.compile(r"\r?\n")
         raw = string.expandtabs(self.raw)
         for line in eol_re.split(raw):
             # Skip ACLs
@@ -495,17 +533,23 @@ class PageFormatter:
                 if line.startswith('#'):
                    continue
                 self.in_header = False
+
             if self.in_pre:
                 print re.sub(pre_re, self.replace, line)
             else:
-                # XXX: Should we check these conditions in this order?
+                if self.in_table and not tr_re.match(line):
+                    self.in_table = False
+                    print '</tbody></table><p>'
+
                 if blank_re.match(line):
                     print '</p><p>'
-                    continue
-                indent = indent_re.match(line)
-                print self._indent_to(len(indent.group(0)))
-                print re.sub(scan_re, self.replace, line)
+                else:
+                    indent = indent_re.match(line)
+                    print self._indent_to(len(indent.group(0)))
+                    print re.sub(scan_re, self.replace, line)
+
         if self.in_pre: print '</pre>'
+        if self.in_table: print '</tbody></table><p>'
         print self._undent()
         print "</p></div>"