- m = re.compile("\[\[(\S+)\ (.+)\]\]").match(word)
- anchor = m.group(1)
- descr = m.group(2)
- if img_re.match(anchor):
- return '<img border="0" src="%s" alt="%s" />' % (anchor, descr)
- elif url_re.match(anchor):
- return '<a href="%s" rel="nofollow" class="external">%s</a>' % (anchor, descr)
- elif anchor.startswith('/'):
- return '<a href="%s">%s</a>' % (anchor, descr)
+ 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 apply(macro, (name, descr))
+ elif img_re.match(name):
+ return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (name, name, descr)
+ elif url_re.match(name):
+ return '<a href="%s" rel="nofollow" class="external">%s</a>' % (name, descr)
+ elif name.startswith('/'):
+ return '<a href="%s">%s</a>' % (name, descr)