X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=46c61c55ad5343f95bbf6541eb959a6cab0f0638;hb=25befe4147c23d55b1ef3fc8af45c719e2e39f8c;hp=aa6d332a449e2b9b3ce481e38c0862f820ce67af;hpb=a0e866e20240e1b4c862a16c1ce798628985b823;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index aa6d332..46c61c5 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -264,10 +264,10 @@ def send_footer(name, mod_string=None): # ---------------------------------------------------------- # Macros -def _macro_TitleSearch(): +def _macro_TitleSearch(*vargs): return _macro_search("titlesearch") -def _macro_FullSearch(): +def _macro_FullSearch(*vargs): return _macro_search("fullsearch") def _macro_search(type): @@ -275,9 +275,9 @@ def _macro_search(type): default = form["value"].value else: default = '' - return """
""" % (type, default) + return """
""" % (type, default) -def _macro_WordIndex(): +def _macro_WordIndex(*vargs): s = make_index_key() pages = list(page_list()) map = {} @@ -310,7 +310,7 @@ def _macro_WordIndex(): return s -def _macro_TitleIndex(): +def _macro_TitleIndex(*vargs): s = make_index_key() pages = list(page_list()) pages.sort() @@ -337,6 +337,7 @@ class PageFormatter: 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 @@ -354,60 +355,61 @@ class PageFormatter: def _tit_repl(self, word): if self.h_level: - result = "" % self.h_level + result = "" % self.h_level self.h_level = 0 else: self.h_level = len(word) - 1 - result = "" % self.h_level + self.h_count += 1 + result = '' % (self.h_count, self.h_level, self.h_count) return result def _rule_repl(self, word): - s = self._undent() - if len(word) <= 3: - s = s + "\n
\n" - else: - s = s + "\n
\n" % (len(word) - 2 ) - return s + return self._undent() + '\n
\n' % (len(word) - 2) def _word_repl(self, word): return Page(word).link_to() def _img_repl(self, word): - return '' % (script_name(), word) + path = script_name() + '/' + word; + return '
' % (path, path) def _url_repl(self, word): if img_re.match(word): - return '' % word + return '' % (word, word) else: return '%s' % (word, word) def _hurl_repl(self, word): - m = re.compile("\[\[(\S+)\ (.+)\]\]").match(word) - anchor = m.group(1) - descr = m.group(2) - if img_re.match(anchor): - return '%s' % (anchor, descr) - elif url_re.match(anchor): - return '%s' % (anchor, descr) - elif anchor.startswith('/'): - return '%s' % (anchor, descr) + m = re.compile("\[\[(\S+)([^\]]*)\]\]").match(word) + name = m.group(1) + descr = m.group(2).strip() or name + + macro = globals().get('_macro_' + name) + if macro: + return apply(macro, (name, descr)) + elif img_re.match(name): + return '%s' % (name, name, descr) + elif url_re.match(name): + return '%s' % (name, descr) + elif name.startswith('/'): + return '%s' % (name, descr) else: - return link_tag(anchor, descr) + return link_tag(name, descr) def _email_repl(self, word): return '%s' % (word, word) + def _html_repl(self, word): + return word; # Pass through def _ent_repl(self, s): return {'&': '&', '<': '<', '>': '>'}[s] - def _li_repl(self, match): return '
  • ' - def _pre_repl(self, word): if word == '{{{' and not self.in_pre: self.in_pre = True @@ -417,8 +419,14 @@ class PageFormatter: return '' return '' - def _hilight_repl(self, word): - return '' + word + '' + def _hi_repl(self, word): + if word == 'FIXME': + cl = 'error' + elif word == 'DONE': + cl = 'success' + elif word == 'TODO': + cl = 'notice' + return '' + word + '' def _var_repl(self, word): if word == '{{' and not self.in_var: @@ -448,11 +456,6 @@ class PageFormatter: return '' return '' - def _macro_repl(self, word): - macro_name = word[2:-2] - # TODO: Somehow get the default value into the search field - return apply(globals()['_macro_' + macro_name], ()) - def _indent_level(self): return len(self.list_indents) and self.list_indents[-1] @@ -495,14 +498,15 @@ class PageFormatter: + r"(?P'{2,3})" + r"|(?P\={2,6})" + r"|(?P^-{3,})" + + r"|(?P<(/|)(div|span|iframe)[^<>]*>)" + r"|(?P[<>&])" - + r"|(?P\b(FIXME|TODO)\b)" + + r"|(?P\b(FIXME|TODO|DONE)\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\[\[\S+\s+.+\]\])" - + r"|(?P(http|ftp|nntp|news|mailto)\:[^\s'\"]+\S)" + + r"|(?P\[\[\S+[^\]]*\]\])" + + r"|(?P(http|https|ftp|mailto)\:[^\s'\"]+\S)" + r"|(?P[-\w._+]+\@[\w.-]+)" # Lists, divs, spans @@ -514,9 +518,6 @@ class PageFormatter: + r"|(?P^\s*\|\|\s*)" + r"|(?P\s*\|\|\s*$)" + r"|(?P\s*\|\|\s*)" - - # Macros - + r"|(?P\[\[(TitleSearch|FullSearch|WordIndex|TitleIndex)\]\])" + r")") pre_re = re.compile( r"(?:"