From 746aad914bdc194bf3905b56d2339250fb11772f Mon Sep 17 00:00:00 2001 From: Bernardo Innocenti Date: Sat, 22 Sep 2007 10:51:46 +0200 Subject: [PATCH] Merge hurl and macros. --- geekigeeki.py | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/geekigeeki.py b/geekigeeki.py index 57992d2..71ce724 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() @@ -373,26 +373,31 @@ class PageFormatter: 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) @@ -454,11 +459,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] @@ -507,8 +507,8 @@ class PageFormatter: # 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 @@ -520,9 +520,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"(?:" -- 2.25.1