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 | |||
@@ -133,7 +133,7 @@ class TextWikiMarkup (WikiMarkup): | |||
133 | length += wsc + wlen | 133 | length += wsc + wlen |
134 | return output + linebuf | 134 | return output + linebuf |
135 | 135 | ||
136 | def fmtelt(self, elt, indent=0): | 136 | def format(self, elt): |
137 | if elt[0] == TEXT: | 137 | if elt[0] == TEXT: |
138 | if isinstance(elt[1],list): | 138 | if isinstance(elt[1],list): |
139 | string = "" | 139 | string = "" |
@@ -204,19 +204,14 @@ class TextWikiMarkup (WikiMarkup): | |||
204 | string += "\n" | 204 | string += "\n" |
205 | elif elt[0] == IND: | 205 | elif elt[0] == IND: |
206 | string = (" " * elt[1]) + self.format(elt[2]) + '\n' | 206 | string = (" " * elt[1]) + self.format(elt[2]) + '\n' |
207 | else: | 207 | elif elt[0] == SEQ: |
208 | string = str(elt) | ||
209 | return string | ||
210 | |||
211 | def format(self, elt, indent=0): | ||
212 | if elt[0] == SEQ: | ||
213 | string = "" | 208 | string = "" |
214 | for x in elt[1]: | 209 | for x in elt[1]: |
215 | if len(string) > 1 and not string[-1].isspace(): | 210 | if len(string) > 1 and not string[-1].isspace(): |
216 | string += ' ' | 211 | string += ' ' |
217 | string += self.format(x, indent) | 212 | string += self.format(x) |
218 | else: | 213 | else: |
219 | string = self.fmtelt(elt, indent) | 214 | string = str(elt) |
220 | return string | 215 | return string |
221 | 216 | ||
222 | def __str__(self): | 217 | def __str__(self): |
@@ -229,24 +224,5 @@ class TextWiktionaryMarkup (TextWikiMarkup): | |||
229 | """ | 224 | """ |
230 | See documentation for HtmlWiktionaryMarkup | 225 | See documentation for HtmlWiktionaryMarkup |
231 | """ | 226 | """ |
227 | # FIXME: It is supposed to do something about templates | ||
232 | 228 | ||
233 | seq_pos = 0 | ||
234 | |||
235 | def str_seq(self, tok, env): | ||
236 | s = "" | ||
237 | self.seq_pos=0 | ||
238 | for t in tok[1:]: | ||
239 | x = self.fmtok(t, env) | ||
240 | if x: | ||
241 | s += x | ||
242 | self.seq_pos += 1 | ||
243 | return s | ||
244 | |||
245 | def str_tmpl(self, tok, env): | ||
246 | arg = self.fmtok(tok[1], env) | ||
247 | if arg and arg != '': | ||
248 | if self.seq_pos > 0: | ||
249 | return arg | ||
250 | else: | ||
251 | return "\n" + arg + ":\n" | ||
252 | |||