diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-03-03 17:08:17 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-03-03 17:08:17 +0200 |
commit | b667a722ceb7db64ed243de706aba795d2a895e9 (patch) | |
tree | 75efb9a939584ae2a87c9b2f31c22b199f538686 | |
parent | 6b0bfa216f6512e929dbe63e6c9b9cb6934dc3c5 (diff) | |
download | wikitrans-b667a722ceb7db64ed243de706aba795d2a895e9.tar.gz wikitrans-b667a722ceb7db64ed243de706aba795d2a895e9.tar.bz2 |
Merge fmtelt with format
-rw-r--r-- | wiki2text.py | 34 |
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 @@ -130,13 +130,13 @@ class TextWikiMarkup (WikiMarkup): 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("."): @@ -201,52 +201,28 @@ class TextWikiMarkup (WikiMarkup): 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" - |