summaryrefslogtreecommitdiffabout
path: root/wiki2text.py
Side-by-side diff
Diffstat (limited to 'wiki2text.py') (more/less context) (ignore whitespace changes)
-rw-r--r--wiki2text.py60
1 files changed, 30 insertions, 30 deletions
diff --git a/wiki2text.py b/wiki2text.py
index 005e551..c94ae51 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -66,9 +66,9 @@ class TextWikiMarkup (WikiMarkup):
return self.html_base % { 'lang' : lang } + urllib.quote(tgt)
def fmtlink(self, elt, istmpl):
- arg = self.format(elt[1][0])
- if len(elt[1]) > 1:
- s = map(self.format, elt[1])
+ arg = self.format(elt['content'][0])
+ if len(elt['content']) > 1:
+ s = map(self.format, elt['content'])
text = s[1]
else:
s = None
@@ -143,10 +143,10 @@ class TextWikiMarkup (WikiMarkup):
return output + linebuf
def format(self, elt):
- if elt[0] == TEXT:
- if isinstance(elt[1],list):
+ if elt['type'] == 'TEXT':
+ if isinstance(elt['content'],list):
string = ""
- for s in elt[1]:
+ for s in elt['content']:
if string:
if string.endswith("."):
string += " "
@@ -154,22 +154,22 @@ class TextWikiMarkup (WikiMarkup):
string += " "
string += s
else:
- string = elt[1]
- elif elt[0] == PARA:
+ string = elt['content']
+ elif elt['type'] == 'PARA':
string = "";
- for x in elt[1]:
+ for x in elt['content']:
string += self.format(x)
string = self.fmtpara(string) + '\n\n'
- elif elt[0] == IT:
+ elif elt['type'] == 'IT':
string = ""
- for x in elt[1]:
+ for x in elt['content']:
s = self.format(x)
if s:
string += " " + s
string = "_" + string.lstrip(" ") + "_"
- elif elt[0] == BOLD:
+ elif elt['type'] == 'BOLD':
string = ""
- for x in elt[1]:
+ for x in elt['content']:
s = self.format(x)
if s:
if string.endswith("."):
@@ -178,36 +178,36 @@ class TextWikiMarkup (WikiMarkup):
string += " "
string += s
string = string.upper()
- elif elt[0] == LINK:
+ elif elt['type'] == 'LINK':
string = self.fmtlink(elt, False)
- elif elt[0] == TMPL:
+ elif elt['type'] == 'TMPL':
s = self.fmtlink(elt, True)
if s:
string = '[' + s + ']'
else:
string = s
- elif elt[0] == BAR:
+ elif elt['type'] == 'BAR':
w = self.width
if w < 5:
w = 5
string = "\n" + ("-" * (w - 5)).center(w - 1) + "\n"
- elif elt[0] == HDR:
- level = elt[1]
+ elif elt['type'] == 'HDR':
+ level = elt['level']
string = "\n" + ("*" * level) + " " + \
- self.format(elt[2]).lstrip(" ") + "\n\n"
- elif elt[0] == REF:
- string = self.xref(self.format(elt[2]), elt[1])
- elif elt[0] == ENV:
- type = elt[1]
- lev = elt[2]
+ self.format(elt['content']).lstrip(" ") + "\n\n"
+ elif elt['type'] == 'REF':
+ string = self.xref(self.format(elt['content']), elt['ref'])
+ elif elt['type'] == 'ENV':
+ type = elt['envtype']
+ lev = elt['level']
if lev > self.width - 4:
lev = 1
string = ""
n = 1
- for s in elt[3]:
+ for s in elt['content']:
if not string.endswith("\n"):
string += "\n"
- x = self.format(s[2])
+ x = self.format(s['content'])
if type == "unnumbered":
string += self.fmtpara(self.indent(lev, "- " + x.lstrip(" ")))
elif type == "numbered":
@@ -221,11 +221,11 @@ class TextWikiMarkup (WikiMarkup):
if not string.endswith("\n"):
string += "\n"
- elif elt[0] == IND:
- string = (" " * elt[1]) + self.format(elt[2]) + '\n'
- elif elt[0] == SEQ:
+ elif elt['type'] == 'IND':
+ string = (" " * elt['level']) + self.format(elt['content']) + '\n'
+ elif elt['type'] == 'SEQ':
string = ""
- for x in elt[1]:
+ for x in elt['content']:
if len(string) > 1 and not string[-1].isspace():
string += ' '
string += self.format(x)

Return to:

Send suggestions and report system problems to the System administrator.