From a0e866e20240e1b4c862a16c1ce798628985b823 Mon Sep 17 00:00:00 2001 From: Bernardo Innocenti Date: Fri, 14 Sep 2007 10:54:11 +0200 Subject: [PATCH] Add wiki tables --- geekigeeki.css | 51 ++++++++++++++++++++++++------ geekigeeki.py | 86 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 106 insertions(+), 31 deletions(-) diff --git a/geekigeeki.css b/geekigeeki.css index e1eb871..49062cd 100755 --- a/geekigeeki.css +++ b/geekigeeki.css @@ -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; diff --git a/geekigeeki.py b/geekigeeki.py index 116b03b..aa6d332 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -107,7 +107,7 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'): """ print "%s: %s" % (site_name, text) - print ' ' + print ' ' if not name: print ' ' 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 ['', ''][self.is_b] + return ['', ''][self.is_b] else: self.is_em = not self.is_em return ['', ''][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 '
'
         elif self.in_pre:
-            self.in_pre = 0
+            self.in_pre = False
             return '
' - else: - return '' + return '' + + def _hilight_repl(self, word): + return '' + word + '' def _var_repl(self, word): if word == '{{' and not self.in_var: - self.in_var = 1 + self.in_var = True return '' elif self.in_var: - self.in_var = 0 + self.in_var = False return '' - else: - return '' + return '' + + def _tr_repl(self, word): + out = '' + if not self.in_table: + self.in_table = True + self.tr_cnt = 0 + out = '

\n' + self.tr_cnt += 1 + return out + '' + return '' + + def _td_repl(self, word): + if self.in_table: + return '^\s*\|\|\s*)" + + r"|(?P\s*\|\|\s*$)" + + r"|(?P
' + + def _tre_repl(self, word): + if self.in_table: + return '
' + 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'{2,3})" + r"|(?P\={2,6})" + + r"|(?P^-{3,})" + r"|(?P[<>&])" + + r"|(?P\b(FIXME|TODO)\b)" + + # Links + r"|(?P\b[a-zA-Z0-9_-]+\.(png|gif|jpg|jpeg|bmp))" + r"|(?P\b(?:[A-Z][a-z]+){2,}\b)" - + r"|(?P^-{3,})" + r"|(?P\[\[\S+\s+.+\]\])" + r"|(?P(http|ftp|nntp|news|mailto)\:[^\s'\"]+\S)" + r"|(?P[-\w._+]+\@[\w.-]+)" + + # Lists, divs, spans + r"|(?P
  • ^\s+\*)" + r"|(?P
    (\{\{\{|\s*\}\}\}))"
                 + r"|(?P(\{\{|\}\}))"
    +
    +            # Tables
    +            + r"|(?P
  • \s*\|\|\s*)" + + # Macros + r"|(?P\[\[(TitleSearch|FullSearch|WordIndex|TitleIndex)\]\])" + r")") pre_re = re.compile( r"(?:" + r"(?P
    \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 '

    ' + if blank_re.match(line): print '

    ' - 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 '' + if self.in_table: print '

    ' print self._undent() print "

    " -- 2.25.1