From: Bernie Innocenti Date: Wed, 8 Apr 2009 16:41:29 +0000 (+0200) Subject: Consolidate legacy syntax rules X-Git-Tag: v4.0~9^2~17 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=aaa8d1b0c0c584f64ab3f1f08a7b8480c05161d4;p=geekigeeki.git Consolidate legacy syntax rules --- diff --git a/geekigeeki.py b/geekigeeki.py index 9f4400f..651d98d 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -30,7 +30,7 @@ import cgi, sys, os, re, errno, stat word_re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$") # FIXME: we accept stuff like foo/../bar and we shouldn't file_re = re.compile(r"^\b([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)\b$") -img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg|bmp|ico)$", re.IGNORECASE) +img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE) video_re = re.compile(r"^.*\.(ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE) url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$") link_re = re.compile("(?:\[\[|{{)([^\s\|]+)(?:\s*\|\s*([^\]]+)|)(?:\]\]|}})") @@ -182,6 +182,8 @@ def send_httperror(status="403 Not Found", query=""): def link_tag(params, text=None, link_class=None, privileged=False): if text is None: text = params # default + elif img_re.match(text): + text = '' if not link_class: if is_external_url(params): @@ -345,19 +347,6 @@ class WikiFormatter: def _rule_repl(self, word): return self._undent() + '\n
\n' % (len(word) - 2) - def _word_repl(self, word): - return link_tag(word) - - def _img_repl(self, word): - pathname = relative_url(word) - return '' % (pathname, pathname) - - def _url_repl(self, word): - if img_re.match(word): - return '' % (word, word) - else: - return '%s' % (word, word) - def _macro_repl(self, word): m = re.compile("\<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>").match(word) name = m.group(1) @@ -380,14 +369,13 @@ class WikiFormatter: def _hurl_repl(self, word): m = link_re.match(word) - name = m.group(1) - descr = m.group(2) - if descr is None: - descr = name - elif img_re.match(m.group(2)): - descr = '' + return link_tag(m.group(1), m.group(2)) + + def _url_repl(self, word): + return link_tag(word) - return link_tag(name, descr) + def _word_repl(self, word): + return link_tag(word) def _inl_repl(self, word): m = link_re.match(word) @@ -409,6 +397,9 @@ class WikiFormatter: else: return '' % (name, name) + def _img_repl(self, word): + return self._inl_repl('{{' + word + '}}') + def _email_repl(self, word): return '%s' % (word, word) @@ -520,7 +511,7 @@ class WikiFormatter: + r"|(?P[<>&])" # Auto links (LEGACY) - + r"|(?P\b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico))" + + r"|(?P\b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt))" + r"|(?P\b(?:[A-Z][a-z]+){2,}\b)" + r"|(?P(http|https|ftp|mailto)\:[^\s'\"]+\S)" + r"|(?P[-\w._+]+\@[\w.-]+)"