diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2015-07-06 08:05:31 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2015-07-06 08:05:31 +0300 |
commit | f3378aebac7e89000ff097ac51c49b62eb6e9f08 (patch) | |
tree | cdf7a9b58b52cd6e995ddf63ef05526e60a918f1 /wiki2text.py | |
parent | 7ab9949e2c038ee6a7215d91896f2b47a5e7c06d (diff) | |
download | wikitrans-f3378aebac7e89000ff097ac51c49b62eb6e9f08.tar.gz wikitrans-f3378aebac7e89000ff097ac51c49b62eb6e9f08.tar.bz2 |
Redo parse tree as a sequence of dictionaries, instead of arrays.
Diffstat (limited to 'wiki2text.py')
-rw-r--r-- | wiki2text.py | 60 |
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 @@ -68,5 +68,5 @@ class TextWikiMarkup (WikiMarkup): 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] @@ -145,6 +145,6 @@ class TextWikiMarkup (WikiMarkup): 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: @@ -156,11 +156,11 @@ class TextWikiMarkup (WikiMarkup): 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) @@ -169,5 +169,5 @@ class TextWikiMarkup (WikiMarkup): 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) @@ -180,5 +180,5 @@ class TextWikiMarkup (WikiMarkup): 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) @@ -188,3 +188,3 @@ class TextWikiMarkup (WikiMarkup): string = s - elif elt[0] == BAR: + elif elt['type'] == 'BAR': w = self.width @@ -193,11 +193,11 @@ class TextWikiMarkup (WikiMarkup): 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: @@ -206,6 +206,6 @@ class TextWikiMarkup (WikiMarkup): 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": @@ -223,7 +223,7 @@ class TextWikiMarkup (WikiMarkup): 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(): |