print '<div class="nav">'
print ' <b>' + site_name + ': ',
if name:
- print link_tag('?fullsearch=' + name, text) + '</b> '
+ print link_tag('?fullsearch=' + name, text, 'navlink') + '</b> '
else:
print text + '</b> '
print ' | ' + link_tag('FrontPage', 'Front Page', 'navlink')
"""
def __init__(self, raw):
self.raw = raw
- self.is_em = self.is_b = 0
self.h_level = 0
- self.h_count = 0
- self.list_indents = []
- self.in_pre = False
- self.in_table = False
- self.tr_cnt = 0
- self.in_var = False
+ self.in_pre = self.in_table = self.in_var = self.in_em = self.in_b = False
self.in_header = True
+ self.list_indents = []
+ self.tr_cnt = self.h_cnt = 0
- def _emph_repl(self, word):
- if len(word) == 3:
- self.is_b = not self.is_b
- return ['</strong>', '<strong>'][self.is_b]
- else:
- self.is_em = not self.is_em
- return ['</em>', '<em>'][self.is_em]
+ 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]
def _tit_repl(self, word):
if self.h_level:
self.h_level = 0
else:
self.h_level = len(word) - 1
- self.h_count += 1
- result = '<h%d id="%d"><a class="heading" href="#%d">*</a> ' % (self.h_level, self.h_count, self.h_count)
+ self.h_cnt += 1
+ result = '<h%d id="%d"><a class="heading" href="#%d">*</a> ' % (self.h_level, self.h_cnt, self.h_cnt)
return result
+ def _br_repl(self, word):
+ return '<br />'
+
def _rule_repl(self, word):
return self._undent() + '\n<hr size="%d" noshade="noshade" />\n' % (len(word) - 2)
return '<a href="%s" rel="nofollow" class="external">%s</a>' % (word, word)
def _hurl_repl(self, word):
- m = re.compile("\[\[(\S+)([^\]]*)\]\]").match(word)
+ m = re.compile("\[\[(\S+)(?:\s*\|\s*([^\]]*)|)\]\]").match(word)
name = m.group(1)
- descr = m.group(2).strip() or name
+ descr = m.group(2) or name
macro = globals().get('_macro_' + name)
if macro:
elif name.startswith('/'):
return '<a href="%s">%s</a>' % (name, descr)
else:
- return link_tag(name, descr)
+ return link_tag(name, descr, 'wikilink')
def _email_repl(self, word):
return '<a href="mailto:%s">%s</a>' % (word, word)
self.tr_cnt = 0
out = '</p><table><tbody>\n'
self.tr_cnt += 1
- return out + '<tr class="' + ['even', 'odd'][self.tr_cnt % 2] + '"><td>'
+ out = out + '<tr class="' + ['even', 'odd'][self.tr_cnt % 2] + '">'
+ return out + ['<td>', '<th>'][word.strip() == '||=']
- def _tre_repl(self, word):
+ def _td_repl(self, word):
if self.in_table:
- return '</td></tr>'
+ return ['</td><td>', '</th><th>'][word.strip() == '||=']
return ''
- def _td_repl(self, word):
+ def _tre_repl(self, word):
if self.in_table:
- return '</td><td>'
+ return ['</td></tr>', '</th></tr>'][word.strip() == '||=']
return ''
def _indent_level(self):
scan_re = re.compile(
r"(?:"
# Formatting
- + r"(?P<emph>'{2,3})"
+ + r"(?P<b>\*\*|''')"
+ + r"|(?P<em>//|'')"
+ r"|(?P<tit>\={2,6})"
+ + r"|(?P<br>\\\\)"
+ r"|(?P<rule>^-{3,})"
+ r"|(?P<html><(/|)(div|span|iframe)[^<>]*>)"
+ r"|(?P<ent>[<>&])"
# 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+[^\]]*\]\])"
+ + r"|(?P<hurl>\[\[(\S+)(?:\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>(\{\{|\}\}))"
+ + r"|(?P<li>^\s+[\*#] +)"
+ + r"|(?P<pre>\{\{\{|\s*\}\}\})"
+ + r"|(?P<var>\{\{|\}\})"
# Tables
- + r"|(?P<tr>^\s*\|\|\s*)"
- + r"|(?P<tre>\s*\|\|\s*$)"
- + r"|(?P<td>\s*\|\|\s*)"
+ + r"|(?P<tr>^\s*\|\|(=|)\s*)"
+ + r"|(?P<tre>\s*\|\|(=|)\s*$)"
+ + r"|(?P<td>\s*\|\|(=|)\s*)"
+ r")")
pre_re = re.compile(
r"(?:"