From: Bernie Innocenti
Date: Fri, 11 Sep 2009 21:46:48 +0000 (-0400)
Subject: Implement numbered lists
X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=96e9789ac9ff9770e7c605555948f23b8ba48b83;p=geekigeeki.git
Implement numbered lists
---
diff --git a/geekigeeki.py b/geekigeeki.py
index 9a05b85..8c9fe64 100755
--- a/geekigeeki.py
+++ b/geekigeeki.py
@@ -373,7 +373,7 @@ class WikiFormatter:
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?
@@ -411,7 +411,7 @@ class WikiFormatter:
return '
'
def _rule_repl(self, word):
- return self._undent() + '\n
\n' % (len(word) - 2)
+ return '\n
\n' % (len(word) - 2)
def _macro_repl(self, word):
try:
@@ -518,31 +518,26 @@ class WikiFormatter:
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 = '
'
while self._indent_level() > new_level:
- del(self.list_indents[-1])
if self.in_li:
s += ''
self.in_li = False # FIXME
- s += '\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 += '' * len(self.list_indents)
- res += ''
- self.list_indents = []
- return res
-
def replace(self, match):
for rule, hit in list(match.groupdict().items()):
if hit:
@@ -594,7 +589,7 @@ class WikiFormatter:
| (?P[<>&])"
)""", 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
@@ -618,12 +613,12 @@ class WikiFormatter:
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('')
if self.in_table: print('')
- print(self._undent())
+ print(self._indent_to(0))
print('
')
class Page: