summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-03 10:08:48 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2009-03-03 10:08:48 (GMT)
commitb5e926d076af2f96cff437ace72c345289d8f92a (patch) (side-by-side diff)
treedb448efe13ab5e0f93da7aa67f1a38b25ca2d099
parentae8b8bc81eab08b2ebe9f8c0957c085b5d45fc2b (diff)
downloadwikitrans-b5e926d076af2f96cff437ace72c345289d8f92a.tar.gz
wikitrans-b5e926d076af2f96cff437ace72c345289d8f92a.tar.bz2
Fix parsing of lists
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--wiki2text.py23
-rw-r--r--wikimarkup.py13
2 files changed, 20 insertions, 16 deletions
diff --git a/wiki2text.py b/wiki2text.py
index c41c4e0..a259157 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -100,17 +100,17 @@ class TextWikiMarkup (WikiMarkup):
return text
def indent (self, lev, text):
- print "T \"",text,"\""
- w = self.width
- self.width = w - lev
if text.find('\n') == -1:
s = (" " * lev) + text
else:
s = ""
for elt in text.split('\n'):
- s += (" " * lev) + elt + '\n'
-
- self.width = w
+ if elt:
+ s += (" " * lev) + elt + '\n'
+ if not text.endswith('\n'):
+ s = s.rstrip('\n')
+# print "IN: '%s'" % (text)
+# print "OUT: '%s'" % (s)
return s
def fmtpara(self, input):
@@ -189,16 +189,19 @@ class TextWikiMarkup (WikiMarkup):
lev = elt[2]
if lev > self.width - 4:
lev = 1
- string = "\n"
+ string = ""
n = 1
for s in elt[3]:
+ if not string.endswith("\n"):
+ string += "\n"
x = self.format(s)
-# print "X",x
if type == ENVUNNUM:
- string += self.indent(lev, "*" + x.lstrip(" ")) + '\n'
+ string += self.indent(lev, "* " + x.lstrip(" "))
elif type == ENVNUM:
- string += self.indent(lev, "%d. %s" % (n, x)) + '\n'
+ string += self.indent(lev, "%d. %s" % (n, x))
n += 1
+ if not string.endswith("\n"):
+ string += "\n"
elif elt[0] == IND:
string = (" " * elt[1]) + self.format(elt[2]) + '\n'
else:
diff --git a/wikimarkup.py b/wikimarkup.py
index 9cfdb09..76fc865 100644
--- a/wikimarkup.py
+++ b/wikimarkup.py
@@ -404,13 +404,14 @@ class BaseWikiMarkup:
elt = self.parse_env(type, len(tok[1]))
else:
elt = self.parse_line()
- if len(tok) == 3:
- if list[-1][0] != SEQ:
- x = list[-1]
- list[-1] = (SEQ, [x])
- list[-1][1].append(elt)
+ if len(tok) == 2:
+ list.append(elt)
continue
- list.append(elt)
+
+ if list[-1][0] != SEQ:
+ x = list[-1]
+ list[-1] = (SEQ, [x])
+ list[-1][1].append(elt)
else:
self.ungetkn()
break

Return to:

Send suggestions and report system problems to the System administrator.