summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-03 17:08:17 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-03-03 17:08:17 +0200
commitb667a722ceb7db64ed243de706aba795d2a895e9 (patch)
tree75efb9a939584ae2a87c9b2f31c22b199f538686
parent6b0bfa216f6512e929dbe63e6c9b9cb6934dc3c5 (diff)
downloadwikitrans-b667a722ceb7db64ed243de706aba795d2a895e9.tar.gz
wikitrans-b667a722ceb7db64ed243de706aba795d2a895e9.tar.bz2
Merge fmtelt with format
-rw-r--r--wiki2text.py34
1 files changed, 5 insertions, 29 deletions
diff --git a/wiki2text.py b/wiki2text.py
index 5ed91fa..09bd86a 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -124,25 +124,25 @@ class TextWikiMarkup (WikiMarkup):
else:
wsc = 1
if length + wsc + wlen > self.width:
# FIXME: fill out linebuf
output += linebuf + '\n'
wsc = 0
length = 0
linebuf = ""
linebuf += " " * wsc + s
length += wsc + wlen
return output + linebuf
- def fmtelt(self, elt, indent=0):
+ def format(self, elt):
if elt[0] == TEXT:
if isinstance(elt[1],list):
string = ""
for s in elt[1]:
if string:
if string.endswith("."):
string += " "
else:
string += " "
string += s.rstrip(" ")
else:
string = elt[1]
@@ -195,58 +195,34 @@ class TextWikiMarkup (WikiMarkup):
if not string.endswith("\n"):
string += "\n"
x = self.format(s)
if type == ENVUNNUM:
string += self.indent(lev, "- " + x.lstrip(" "))
elif type == ENVNUM:
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:
- string = str(elt)
- return string
-
- def format(self, elt, indent=0):
- if elt[0] == SEQ:
+ elif elt[0] == SEQ:
string = ""
for x in elt[1]:
if len(string) > 1 and not string[-1].isspace():
string += ' '
- string += self.format(x, indent)
+ string += self.format(x)
else:
- string = self.fmtelt(elt, indent)
+ string = str(elt)
return string
def __str__(self):
str = ""
for elt in self.tree:
str += self.format(elt)
return str
class TextWiktionaryMarkup (TextWikiMarkup):
"""
See documentation for HtmlWiktionaryMarkup
"""
+ # FIXME: It is supposed to do something about templates
- seq_pos = 0
-
- def str_seq(self, tok, env):
- s = ""
- self.seq_pos=0
- for t in tok[1:]:
- x = self.fmtok(t, env)
- if x:
- s += x
- self.seq_pos += 1
- return s
-
- def str_tmpl(self, tok, env):
- arg = self.fmtok(tok[1], env)
- if arg and arg != '':
- if self.seq_pos > 0:
- return arg
- else:
- return "\n" + arg + ":\n"
-

Return to:

Send suggestions and report system problems to the System administrator.