summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-03 10:46:32 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2009-03-03 10:46:32 (GMT)
commit6b0bfa216f6512e929dbe63e6c9b9cb6934dc3c5 (patch) (side-by-side diff)
tree2d730aa5e4afa504bc454f875da21052ee2f914b
parentb5e926d076af2f96cff437ace72c345289d8f92a (diff)
downloadwikitrans-6b0bfa216f6512e929dbe63e6c9b9cb6934dc3c5.tar.gz
wikitrans-6b0bfa216f6512e929dbe63e6c9b9cb6934dc3c5.tar.bz2
Fix it/bold parsing + minor bugfixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--wiki2text.py12
-rw-r--r--wikimarkup.py43
2 files changed, 43 insertions, 12 deletions
diff --git a/wiki2text.py b/wiki2text.py
index a259157..5ed91fa 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -172,7 +172,7 @@ class TextWikiMarkup (WikiMarkup):
elif elt[0] == LINK:
string = self.fmtlink(elt, False)
elif elt[0] == TMPL:
- string = '\n' + self.fmtlink(elt, True) + '\n'
+ string = '[' + self.fmtlink(elt, True) + ']'
elif elt[0] == BAR:
w = self.width
if w < 5:
@@ -196,7 +196,7 @@ class TextWikiMarkup (WikiMarkup):
string += "\n"
x = self.format(s)
if type == ENVUNNUM:
- string += self.indent(lev, "* " + x.lstrip(" "))
+ string += self.indent(lev, "- " + x.lstrip(" "))
elif type == ENVNUM:
string += self.indent(lev, "%d. %s" % (n, x))
n += 1
@@ -209,12 +209,14 @@ class TextWikiMarkup (WikiMarkup):
return string
def format(self, elt, indent=0):
- string = ""
if elt[0] == SEQ:
+ string = ""
for x in elt[1]:
- string += " " + self.format(x, indent)
+ if len(string) > 1 and not string[-1].isspace():
+ string += ' '
+ string += self.format(x, indent)
else:
- string += " " + self.fmtelt(elt, indent)
+ string = self.fmtelt(elt, indent)
return string
def __str__(self):
diff --git a/wikimarkup.py b/wikimarkup.py
index 76fc865..baa5c82 100644
--- a/wikimarkup.py
+++ b/wikimarkup.py
@@ -156,6 +156,16 @@ class BaseWikiMarkup:
self.dprint(80, "LEAVE parse_bold=None")
return None
seq.append(x)
+ elif self.is_inline_delim(tok):
+ if textlist:
+ seq.append((TEXT, textlist))
+ textlist = []
+ x = self.parse_inline(tok)
+ if x:
+ seq.append(x)
+ else:
+ self.dprint(80, "LEAVE parse_bold=%s", "None")
+ return None
else:
self.dprint(80, "LEAVE parse_bold=None")
return None
@@ -198,11 +208,21 @@ class BaseWikiMarkup:
if textlist:
seq.append((TEXT, textlist))
textlist = []
- x = self.parse_bold(True)
- if not x:
- self.dprint(80, "LEAVE parse_it=%s", "None")
- return None
- seq.append(x)
+ x = self.parse_bold(True)
+ if not x:
+ self.dprint(80, "LEAVE parse_it=%s", "None")
+ return None
+ seq.append(x)
+ elif self.is_inline_delim(tok):
+ if textlist:
+ seq.append((TEXT, textlist))
+ textlist = []
+ x = self.parse_inline(tok)
+ if x:
+ seq.append(x)
+ else:
+ self.dprint(80, "LEAVE parse_it=%s", "None")
+ return None
else:
self.dprint(80, "LEAVE parse_it=%s", "None")
return None
@@ -282,6 +302,12 @@ class BaseWikiMarkup:
return ret
inline_delims = [ "''", "'''", "[", "[[", "{{" ]
+
+ def is_inline_delim(self, tok):
+ return tok[0] == DELIM and tok[1] in self.inline_delims
+ def is_block_delim(self, tok):
+ return tok[0] == DELIM and tok[1] not in self.inline_delims
+
def parse_inline(self, tok):
self.dprint(80, "ENTER parse_inline(%s), tok %s", tok, self.peektkn())
tokind = self.tokind
@@ -317,10 +343,12 @@ class BaseWikiMarkup:
break
else:
self.ungetkn()
+ if self.is_block_delim(tok):
+ break
elif tok[0] == NIL:
break
elif tok[0] == DELIM:
- if tok[1] in self.inline_delims:
+ if self.is_inline_delim(tok):
if textlist:
seq.append((TEXT, textlist))
textlist = []
@@ -331,7 +359,8 @@ class BaseWikiMarkup:
seq.append(tok)
break
else:
- self.ungetkn()
+ seq.append((TEXT,tok[1]))
+ # self.ungetkn()
break
if textlist:
seq.append((TEXT, textlist))

Return to:

Send suggestions and report system problems to the System administrator.