-#! /usr/bin/env python
+#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 1999, 2000 Martin Pool <mbp@humbug.org.au>
print ' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />'
if not name:
print ' <meta name="robots" content="noindex,nofollow" />'
- if globals().has_key('css_url'):
- print ' <link rel="stylesheet" type="text/css" href="%s" />' % css_url
+ for css in css_url:
+ print ' <link rel="stylesheet" type="text/css" href="%s" />' % css
print '</head>'
# Body
def __init__(self, raw):
self.raw = raw
self.h_level = 0
- self.in_pre = self.in_table = self.in_var = self.in_em = self.in_b = False
+ self.in_pre = self.in_table = False
self.in_header = True
self.list_indents = []
self.tr_cnt = self.h_cnt = 0
+ self.styles = {
+ #wiki html enabled?
+ "//": ["em", False],
+ "''": ["em", False],
+ "**": ["b", False],
+ "'''": ["b", False],
+ "##": ["tt", False],
+ "``": ["tt", False],
+ "__": ["u", False],
+ "^^": ["sup", False],
+ ",,": ["sub", False]
+ }
def _b_repl(self, word):
- self.in_b = not self.in_b
- return ['</strong>', '<strong>'][self.in_b]
-
- def _em_repl(self, word):
- self.in_em = not self.in_em
- return ['</em>', '<em>'][self.in_em]
+ style = self.styles[word]
+ style[1] = not style[1]
+ return ['</','<'][style[1]] + style[0] + '>'
def _tit_repl(self, word):
if self.h_level:
return '<a href="%s" rel="nofollow" class="external">%s</a>' % (word, word)
def _hurl_repl(self, word):
- m = re.compile("\[\[(\S+)(?:\s*\|\s*([^\]]*)|)\]\]").match(word)
+ m = re.compile("\[\[([^ \t\n\r\f\v\|]+)(?:\s*\|\s*([^\]]+)|)\]\]").match(word)
name = m.group(1)
descr = m.group(2) or 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)
+ return '<div class="thumb"><a href="%s"><img border="0" src="%s" alt="%s" /></a><div class="caption">%s</div></div>' % (name, name, descr, descr)
else:
- return link_tag(name, descr, 'wikilink')
+ if img_re.match(descr):
+ descr = '<img border="0" src="' + descr + '" />'
+
+ if 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)
+ else:
+ return link_tag(name, descr, 'wikilink')
def _email_repl(self, word):
return '<a href="mailto:%s">%s</a>' % (word, word)
cl = 'notice'
return '<strong class="highlight ' + cl + '">' + word + '</strong>'
- def _var_repl(self, word):
- if word == '{{' and not self.in_var:
- self.in_var = True
- return '<code>'
- elif self.in_var:
- self.in_var = False
- return '</code>'
- return ''
-
def _tr_repl(self, word):
out = ''
if not self.in_table:
scan_re = re.compile(
r"(?:"
# Formatting
- + r"(?P<b>\*\*|''')"
- + r"|(?P<em>//|'')"
+ + r"(?P<b>\*\*|'''|//|''|##|``|__|\^\^|,,)"
+ r"|(?P<tit>\={2,6})"
+ r"|(?P<br>\\\\)"
+ r"|(?P<rule>^-{3,})"
# Links
+ r"|(?P<img>\b[a-zA-Z0-9_-]+\.(png|gif|jpg|jpeg|bmp))"
+ r"|(?P<word>\b(?:[A-Z][a-z]+){2,}\b)"
- + r"|(?P<hurl>\[\[(\S+)(?:\s*\|\s*([^\]]*)|)\]\])"
+ + r"|(?P<hurl>\[\[([^ \t\n\r\f\v\|]+)(?:\s*\|\s*([^\]]+)|)\]\])"
+ r"|(?P<url>(http|https|ftp|mailto)\:[^\s'\"]+\S)"
+ r"|(?P<email>[-\w._+]+\@[\w.-]+)"
# Lists, divs, spans
+ r"|(?P<li>^\s+[\*#] +)"
+ r"|(?P<pre>\{\{\{|\s*\}\}\})"
- + r"|(?P<var>\{\{|\}\})"
# Tables
+ r"|(?P<tr>^\s*\|\|(=|)\s*)"
self.page_name = page_name
self.msg = ''
self.msg_type = 'error'
- self.attrs = {}
def split_title(self):
# look for the end of words and the start of a new word,
raise er
def get_attrs(self):
- if self.attrs:
+ if self.__dict__.has_key('attrs'):
return self.attrs
+ self.attrs = {}
try:
file = open(self._text_filename(), 'rt')
attr_re = re.compile(r"^#(\S*)(.*)$")
raise er
return self.attrs
+ def get_attr(self, name, default):
+ if self.get_attrs().has_key(name):
+ return self.get_attrs()[name]
+ else:
+ return default
+
def can(self, action, default=True):
- attrs = self.get_attrs()
try:
- # SomeUser:read,write All:read
- acl = attrs["acl"]
+ #acl SomeUser:read,write All:read
+ acl = self.get_attr("acl", None)
for rule in acl.split():
(user,perms) = rule.split(':')
if user == remote_user() or user == "All":
page_name = None
if self.can_write():
page_name = self.page_name
+
+ #FIXME: are there security implications?
+ #css foo.css bar.css
+ global css_url
+ css_url = css_url + self.get_attr("css", "").split()
+
send_title(page_name, self.split_title(), msg=self.msg, msg_type=self.msg_type)
if self.can_read():
PageFormatter(self.get_raw_body()).print_html()