From: Bernie Innocenti Date: Mon, 2 Jun 2008 12:21:46 +0000 (+0200) Subject: Implement Creole syntax for macros. X-Git-Tag: v3.0~20 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=4b7dd02a651033602a4e092a981a973dd20573e7;p=geekigeeki.git Implement Creole syntax for macros. --- diff --git a/geekigeeki.py b/geekigeeki.py index be262f9..ca59dcc 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -265,19 +265,14 @@ def send_footer(name, mod_string=None): print '' # Macros ------------------------------------------------------------ -def _macro_TitleSearch(*vargs): - return _macro_search("titlesearch") - -def _macro_FullSearch(*vargs): - return _macro_search("fullsearch") - -def _macro_search(type): - default = '' - if 'value' in form: - default = form['value'].value - return """
""" % (type, default) - -def _macro_WordIndex(*vargs): +def _macro_HttpGet(argv): + if argv[1] in form: + return form[argv[1]].value + elif len(argv) > 2: + return argv[2] # default value + return '' + +def _macro_WordIndex(argv): s = make_index_key() pages = list(page_list()) map = {} @@ -309,8 +304,7 @@ def _macro_WordIndex(*vargs): s = s + '' return s - -def _macro_TitleIndex(*vargs): +def _macro_TitleIndex(argv): s = make_index_key() pages = list(page_list()) pages.sort() @@ -334,7 +328,7 @@ class PageFormatter: def __init__(self, raw): self.raw = raw self.h_level = 0 - self.in_pre = self.in_table = self.in_li = False + self.in_pre = self.in_html = self.in_table = self.in_li = False self.in_header = True self.list_indents = [] self.tr_cnt = 0 @@ -386,28 +380,25 @@ class PageFormatter: return '%s' % (word, word) def _macro_repl(self, word): - m = re.compile("<<([^\s\|]+)(?:\s*\|\s*([^\]]+)|)>>").match(word) + m = re.compile("\<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>").match(word) name = m.group(1) - param = m.group(2) or None + argv = [name] + if m.group(2): + argv.extend(m.group(2).split('|')) + argv = map(str.strip, argv) macro = globals().get('_macro_' + name) if macro: - return macro(name, param) + return macro(argv) else: - param_str = '' - if param: - param_str = param + ' ' - return '' + name + param_str + '' + return '<<' + '|'.join(argv) + '>>' def _hurl_repl(self, word): m = re.compile("\[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\]").match(word) name = m.group(1) descr = m.group(2) or name - macro = globals().get('_macro_' + name) - if macro: - return macro(name, descr) - elif img_re.match(name): + if img_re.match(name): name = relative_url(name) # The "extthumb" nonsense works around a limitation of the HTML block model return '
%s
%s
' % (name, name, descr, descr) @@ -421,9 +412,13 @@ class PageFormatter: return '%s' % (word, word) def _html_repl(self, word): + self.in_html += 1 return word; # Pass through def _ent_repl(self, s): + if self.in_html and s == '>': + self.in_html -= 1 + return '>' return {'&': '&', '<': '<', '>': '>'}[s] @@ -513,17 +508,17 @@ class PageFormatter: + r"|(?P\={2,6})" + r"|(?P
\\\\)" + r"|(?P^-{3,})" + + r"|(?P\b(FIXME|TODO|DONE)\b)" # Links - + r"|(?P<<([^\s\|]+)(?:\s*\|\s*([^\]]+)|)>>)" + + r"|(?P\<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)" + r"|(?P\[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])" # Inline HTML - + r"|(?P<(/|)(div|span|iframe)[^<>]*>)" + + r"|(?P<(/|)(div|span|iframe|form|input))" + r"|(?P[<>&])" - + r"|(?P\b(FIXME|TODO|DONE)\b)" - # Links + # Auto links + r"|(?P\b[a-zA-Z0-9_-]+\.(png|gif|jpg|jpeg|bmp))" # LEGACY + r"|(?P\b(?:[A-Z][a-z]+){2,}\b)" # LEGACY + r"|(?P(http|https|ftp|mailto)\:[^\s'\"]+\S)" # LEGACY