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*([^\]]+)|)(?:\]\]|}})")
title_done = False
-
# CGI stuff ---------------------------------------------------------
-
def script_name():
return os.environ.get('SCRIPT_NAME', '')
+def query_string():
+ path_info = os.environ.get('PATH_INFO', '')
+ if len(path_info) and path_info[0] == '/':
+ return path_info[1:] or 'FrontPage'
+ else:
+ return os.environ.get('QUERY_STRING', '') or 'FrontPage'
+
def privileged_path():
return privileged_url or script_name()
def link_tag(params, text=None, link_class=None, privileged=False):
if text is None:
text = params # default
+ elif img_re.match(text):
+ text = '<img border="0" src="' + text + '" />'
if not link_class:
if is_external_url(params):
def _rule_repl(self, word):
return self._undent() + '\n<hr size="%d" noshade="noshade" />\n' % (len(word) - 2)
- def _word_repl(self, word):
- return link_tag(word)
-
- def _img_repl(self, word):
- pathname = relative_url(word)
- return '<a href="%s"><img border="0" src="%s" /></a>' % (pathname, pathname)
-
- def _url_repl(self, word):
- if img_re.match(word):
- return '<a href="%s"><img border="0" src="%s" /></a>' % (word, word)
- else:
- return '<a href="%s" rel="nofollow" class="external">%s</a>' % (word, word)
-
def _macro_repl(self, word):
m = re.compile("\<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>").match(word)
name = m.group(1)
if macro:
return macro(argv)
else:
- return '<strong class="error"><<' + '|'.join(argv) + '>></strong>'
+ msg = '<<' + '|'.join(argv) + '>>'
+ if not self.in_html:
+ msg = '<strong class="error">' + msg + '</strong>'
+ return msg
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 = '<img border="0" src="' + descr + '" />'
+ return link_tag(m.group(1), m.group(2))
- return link_tag(name, descr)
+ def _url_repl(self, word):
+ return link_tag(word)
+
+ def _word_repl(self, word):
+ return link_tag(word)
def _inl_repl(self, word):
m = link_re.match(word)
else:
return '<a href="%s"><img border="0" src="%s" /></a>' % (name, name)
+ def _img_repl(self, word):
+ return self._inl_repl('{{' + word + '}}')
+
def _email_repl(self, word):
return '<a href="mailto:%s">%s</a>' % (word, word)
self.in_html += 1
return word; # Pass through
+ def _htmle_repl(self, word):
+ self.in_html -= 1
+ return word; # Pass through
+
def _ent_repl(self, s):
- if self.in_html and s == '>':
- self.in_html -= 1
- return '>'
+ if self.in_html:
+ return s; # Pass through
return {'&': '&',
'<': '<',
'>': '>'}[s]
def print_html(self):
print '<div class="wiki"><p>'
- # For each line, we scan through looking for magic
- # strings, outputting verbatim any intervening text
- # TODO: highlight search words (look at referrer)
- scan_re = re.compile(
- r"(?:"
- # Formatting
- + r"(?P<b>\*\*|'''|//|''|##|``|__|\^\^|,,)"
- + r"|(?P<tit>\={2,6})"
- + r"|(?P<br>\\\\)"
- + r"|(?P<rule>^-{3,})"
- + r"|(?P<hi>\b(FIXME|TODO|DONE)\b)"
+ scan_re = re.compile(r"""(?:
+ # Styles and formatting
+ (?P<b> \*\*|'''|//|''|\#\#|``|__|\^\^|,,)
+ | (?P<tit> \={2,6})
+ | (?P<br> \\\\)
+ | (?P<rule> ^-{3,})
+ | (?P<hi> \b( FIXME | TODO | DONE )\b )
# Links
- + r"|(?P<macro>\<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)"
- + r"|(?P<hurl>\[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])"
+ | (?P<macro> \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)
+ | (?P<hurl> \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])
# Inline HTML
- + r"|(?P<html><(/|)(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])[^>]*>)"
- + r"|(?P<ent>[<>&])"
+ | (?P<html> <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
+ | (?P<htmle> ( /\s*> | </(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])> ) )
+ | (?P<ent> [<>&] )
# Auto links (LEGACY)
- + r"|(?P<img>\b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico))"
- + r"|(?P<word>\b(?:[A-Z][a-z]+){2,}\b)"
- + r"|(?P<url>(http|https|ftp|mailto)\:[^\s'\"]+\S)"
- + r"|(?P<email>[-\w._+]+\@[\w.-]+)"
+ | (?P<img> \b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt))
+ | (?P<word> \b(?:[A-Z][a-z]+){2,}\b)
+ | (?P<url> (http|https|ftp|mailto)\:[^\s'\"]+\S)
+ | (?P<email> [-\w._+]+\@[\w.-]+)
# Lists, divs, spans
- + r"|(?P<li>^\s+[\*#] +)"
- + r"|(?P<pre>\{\{\{|\s*\}\}\})"
- + r"|(?P<inl>\{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})"
+ | (?P<li> ^\s+[\*\#]\s+)
+ | (?P<pre> \{\{\{|\s*\}\}\})
+ | (?P<inl> \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
# Tables
- + r"|(?P<tr>^\s*\|\|(=|)\s*)"
- + r"|(?P<tre>\s*\|\|(=|)\s*$)"
- + r"|(?P<td>\s*\|\|(=|)\s*)"
- + r")")
- pre_re = re.compile(
- r"(?:"
- + r"(?P<pre>\s*\}\}\})"
- + r"|(?P<ent>[<>&])"
- + r")")
+ | (?P<tr> ^\s*\|\|(=|)\s*)
+ | (?P<tre> \s*\|\|(=|)\s*$)
+ | (?P<td> \s*\|\|(=|)\s*)
+
+ # TODO: highlight search words (look at referrer)
+ )""", re.VERBOSE)
+ pre_re = re.compile("""(?:
+ (?P<pre>\s*\}\}\})
+ | (?P<ent>[<>&])"
+ )""", re.VERBOSE)
blank_re = re.compile(r"^\s*$")
indent_re = re.compile(r"^\s*")
tr_re = re.compile(r"^\s*\|\|")
eol_re = re.compile(r"\r?\n")
+
+ # For each line, we scan through looking for magic strings, outputting verbatim any intervening text
for self.line in eol_re.split(self.raw.expandtabs()):
# Skip pragmas
if self.in_header:
handler(form[cmd].value)
break
else:
- path_info = os.environ.get('PATH_INFO', '')
- if len(path_info) and path_info[0] == '/':
- query = path_info[1:] or 'FrontPage'
- else:
- query = os.environ.get('QUERY_STRING', '') or 'FrontPage'
-
+ query = query_string()
if file_re.match(query):
if word_re.match(query):
Page(query).format()