From: Bernie Innocenti Date: Sat, 2 May 2009 06:19:18 +0000 (+0200) Subject: Fix corner cases of humanized links X-Git-Tag: v4.0~7 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=8d7f457924b6c4bde8486d1fd413516082ceedf9;p=geekigeeki.git Fix corner cases of humanized links --- diff --git a/geekigeeki.py b/geekigeeki.py index b52d352..678754e 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -79,7 +79,7 @@ def permalink(s): return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip()) def humanlink(s): - return re.search('([^:/\.]+)(?:\.[^/:]+|)$', s).group(1).replace('_', ' ') + return re.sub(r'([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' ')) # Split arg lists like "blah| blah blah| width=100 | align = center", # return a list containing anonymous arguments and a map containing the named arguments @@ -87,10 +87,10 @@ def parse_args(s): args = [] kwargs = {} for arg in s.strip('<[{}]>').split('|'): - try: - key, val = arg.split('=', 1) - kwargs[key.strip()] = val.strip() - except ValueError: + m = re.match('\s*(\w+)\s*=\s*(.+)\s*', arg) + if m is not None: + kwargs[m.group(1)] = m.group(2) + else: args.append(arg.strip()) return (args, kwargs) @@ -173,7 +173,7 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal print(' | Page History') if name: - print(' | ' + link_tag('?raw=' + name, 'Raw Text', cssclass='navlink')) + print(' | ' + link_tag(name + '?a=raw', 'Raw Text', cssclass='navlink')) if privileged_url is not None: if writable: print(' | ' + link_tag('?a=edit&q=' + name, 'Edit', cssclass='navlink', privileged=True))