self.h_level = 0
self.in_pre = self.in_html = self.in_table = self.in_li = False
self.in_header = True
- self.list_indents = []
+ self.list_indents = [] # a list of pairs (indent_level, list_type) to track nested lists
self.tr_cnt = 0
self.styles = {
#wiki html enabled?
return '<br />'
def _rule_repl(self, word):
- return self._undent() + '\n<hr size="%d" noshade="noshade" />\n' % (len(word) - 2)
+ return '\n<hr size="%d" noshade="noshade" />\n' % (len(word) - 2)
def _macro_repl(self, word):
try:
return ''
def _indent_level(self):
- return len(self.list_indents) and self.list_indents[-1]
+ return len(self.list_indents) and self.list_indents[-1][0]
- def _indent_to(self, new_level):
+ def _indent_to(self, new_level, list_type=''):
if self._indent_level() == new_level:
return ''
s = '</p>'
while self._indent_level() > new_level:
- del(self.list_indents[-1])
if self.in_li:
s += '</li>'
self.in_li = False # FIXME
- s += '</ul>\n'
+ s += '</' + self.list_indents[-1][1] + '>\n'
+ del(self.list_indents[-1])
+
+ list_type = ('ul', 'ol')[list_type == '#']
while self._indent_level() < new_level:
- self.list_indents.append(new_level)
- s += '<ul>\n'
+ self.list_indents.append((new_level, list_type))
+ s += '<' + list_type + '>\n'
s += '<p>'
return s
- def _undent(self):
- res = '</p>'
- res += '</ul>' * len(self.list_indents)
- res += '<p>'
- self.list_indents = []
- return res
-
def replace(self, match):
for rule, hit in list(match.groupdict().items()):
if hit:
| (?P<ent>[<>&])"
)""", re.VERBOSE)
blank_re = re.compile(r"^\s*$")
- indent_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
else:
indent = indent_re.match(self.line)
#3.0: print(self._indent_to(len(indent.group(0))), end=' ')
- print(self._indent_to(len(indent.group(0))))
+ print(self._indent_to(len(indent.group(1)), indent.group(2)))
print(re.sub(scan_re, self.replace, self.line))
if self.in_pre: print('</pre>')
if self.in_table: print('</tbody></table><p>')
- print(self._undent())
+ print(self._indent_to(0))
print('</p></div>')
class Page: