From ba587c4d137fd9a6765106d6d723403c76f5ec23 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Thu, 9 Apr 2009 00:56:25 +0200 Subject: [PATCH] Add support for including wiki pages inline through {{...}} --- geekigeeki.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/geekigeeki.py b/geekigeeki.py index 4fb96cb..5bae68b 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -33,7 +33,8 @@ 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|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*([^\]]+)|)(?:\]\]|}})") +link_re = re.compile(r"(?:\[\[|{{)([^\s\|]+)(?:\s*\|\s*([^\]]+)|)(?:\]\]|}})") +ext_re = re.compile(r"\.([^\./]+)$") title_done = False @@ -208,10 +209,16 @@ def link_tag(params, text=None, link_class=None, privileged=False): def link_inline(name, descr=None, args=''): if not descr: descr = name + url = relative_url(name) if video_re.match(name): - return '' % name + return '' % url + elif img_re.match(name): + return '%s' % (url, url + args, descr) + elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page + return Page(name).send_naked() else: - return '%s' % (name, name + args, descr) + return '' \ + % (url, url, name) # Search --------------------------------------------------- @@ -387,9 +394,7 @@ class WikiFormatter: return link_tag(m.group(1), m.group(2)) def _inl_repl(self, word): - m = link_re.match(word) - name = relative_url(m.group(1)) - descr = m.group(2) + (name, descr) = link_re.match(word).groups() if descr: argv = descr.split('|') @@ -606,12 +611,14 @@ class Page: return False raise err - def get_raw_body(self): + def get_raw_body(self, default=None): try: return open(self._filename(), 'rb').read() except IOError, err: if err.errno == errno.ENOENT: - return '' # just doesn't exist, use default + if default is None: + default = '//[[?edit=%s|Describe %s]]//' % (self.page_name, self.page_name) + return default if err.errno == errno.EISDIR: return self.format_dir() raise err @@ -719,7 +726,8 @@ class Page: print '
' % relative_url(self.page_name) print '' % (self.page_name) print '
' % (self.page_name) - print '' % cgi.escape(preview or self.get_raw_body()) + print '' \ + % cgi.escape(preview or self.get_raw_body(default='')) print ' ' % filename print """
-- 2.25.1