diff options
Diffstat (limited to 'wikitrans/wiki2text.py')
-rw-r--r-- | wikitrans/wiki2text.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/wikitrans/wiki2text.py b/wikitrans/wiki2text.py index 88e7610..7585bff 100644 --- a/wikitrans/wiki2text.py +++ b/wikitrans/wiki2text.py @@ -35,6 +35,7 @@ try: except ImportError: from urllib.parse import quote as url_quote + class TextSeqNode(WikiSeqNode): def format(self): string = "" @@ -44,6 +45,7 @@ class TextSeqNode(WikiSeqNode): string += x.format() return string + class TextTextNode(WikiTextNode): def format(self): if isinstance(self.content, list): @@ -59,6 +61,7 @@ class TextTextNode(WikiTextNode): string = self.content return string + class TextPreNode(WikiSeqNode): def format(self): string = "" @@ -67,6 +70,7 @@ class TextPreNode(WikiSeqNode): string += '\n' return string + class TextParaNode(WikiSeqNode): def format(self): string = "" @@ -75,6 +79,7 @@ class TextParaNode(WikiSeqNode): string = self.parser.fmtpara(string) + '\n\n' return string + class TextItNode(WikiSeqNode): def format(self): string = "" @@ -84,6 +89,7 @@ class TextItNode(WikiSeqNode): string += " " + s return "_" + string.lstrip(" ") + "_" + class TextBoldNode(WikiSeqNode): def format(self): string = "" @@ -95,6 +101,7 @@ class TextBoldNode(WikiSeqNode): string += x.format() return string.upper() + class TextLinkNode(WikiSeqNode): def format(self): arg = self.content[0].format() @@ -139,10 +146,12 @@ class TextLinkNode(WikiSeqNode): else: return text + class TextTmplNode(TextLinkNode): def format(self): return '[' + super(TextTmplNode, self).format() + ']' + class TextBarNode(WikiNode): def format(self): w = self.parser.width @@ -150,6 +159,7 @@ class TextBarNode(WikiNode): w = 5 return "\n" + ("-" * (w - 5)).center(w - 1) + "\n" + class TextHdrNode(WikiHdrNode): def format(self): return ("\n" @@ -158,6 +168,7 @@ class TextHdrNode(WikiHdrNode): + self.content.format().lstrip(" ") + "\n\n") + class TextRefNode(WikiRefNode): def format(self): text = self.content.format() @@ -166,6 +177,7 @@ class TextRefNode(WikiRefNode): else: return "see " + self.ref + class TextEnvNode(WikiEnvNode): def format(self): type = self.envtype @@ -188,16 +200,16 @@ class TextEnvNode(WikiEnvNode): string += self.parser.indent(lev-1, x) else: string += self.parser.indent(lev+3, x) - if not string.endswith("\n"): string += "\n" - return string + class TextIndNode(WikiIndNode): def format(self): return (" " * self.level) + self.content.format() + '\n' + class TextTagNode(WikiTagNode): def format(self): if self.tag == 'code': @@ -338,6 +350,7 @@ class TextWikiMarkup(WikiMarkup): str += elt.format() return str + class TextWiktionaryMarkup(TextWikiMarkup): """A class for translating Wiktionary articles into plain text. @@ -345,4 +358,3 @@ class TextWiktionaryMarkup(TextWikiMarkup): """ html_base='http://%(lang)s.wiktionary.org/wiki/' - |