1 """
   2     MoinMoin - NewWindow Macro
   3 
   4     Copyright (c) 2000-2001 by Changjune Kim <juneaftn@orgio.net>
   5     All rights reserved, see COPYING for details.
   6 
   7     [[NewWindow("url"[, "linkname"])]]
   8         Pops up a new window when clicked on
   9 
  10     $Id: NewWindow.py,v 0.8 2001/05/16 04:07:13 
  11 """
  12 
  13 # Imports
  14 import cgi, re
  15 from MoinMoin import config, user, wikiutil
  16 
  17 _args_re_pattern = r'(?P<hq1>[\'"])(?P<url>[^\'"]+)((?P<spacer>[\'"],\s*)(?P<hquote>[\'"])(?P<htext>.+?)(?P=hquote))?'
  18 
  19 
  20 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
  21     if not text:
  22         return ('<p><strong class="error">URL Needed!</strong></p>')
  23 
  24     # parse and check arguments
  25     args = args_re.match(text)
  26     if not args:
  27         return '<p><strong class="error">Invalid NewWindow arguments "%s"!</strong></p>' % (text,)
  28 
  29     url = args.group('url')
  30     htext= args.group('htext')
  31     if not htext:
  32         htext=url
  33     result='<a href="%s" target="_blank">'%cgi.escape(url,1)
  34     result+='<img src="%s/img/moin-www.gif" width="11" height="11" border="0" hspace="4" alt="[new window]">%s</a>'\
  35            %(config.url_prefix, htext)
  36     return result

MoinMoin: macro/NewWindow.py (last edited 2007-10-29 19:21:47 by localhost)