summaryrefslogtreecommitdiff
path: root/wiki2text.py
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-07-06 17:01:23 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2015-07-06 17:36:49 +0300
commitb74b1d5fe2326f56a2e37f57c38b929307c71282 (patch)
treee6029ae08f00bc7affcd1d7aec75d1288f9184ea /wiki2text.py
parentf3378aebac7e89000ff097ac51c49b62eb6e9f08 (diff)
downloadwikitrans-b74b1d5fe2326f56a2e37f57c38b929307c71282.tar.gz
wikitrans-b74b1d5fe2326f56a2e37f57c38b929307c71282.tar.bz2
Handle <tags> and implicit preformatted blocks
Among <tags>, this commit handles <nowiki> and <code>. General tag handling mechanism is provided. * wikimarkup.py (otag, ctag, close_delim): New variables. (BaseWikiMarkup)<newline,nested>: New attributes. (otag, ctag, close_delim): New variables. (newline,nested>: New attributes. (input_tag): New abstract method. (tokread): Remove calls to dprint, now done by the callers. Handle xml-style tags. (getkn,ungetkn): Set newline. (inline_delims): Add '|' (parse_para): Decide whether it is going to be a PRE or PARA. Don't mix the two. Fix recovery in case of unmatched/incorrect inline constructs. (parse): eliminate initial PARA, if called as a nested instance. (WikiMarkup): Remove parse method. Rely on the parent class. * wiki2html.py (input_tag, str_tag, str_pre): New methods. (format): Handle PRE and TAG tokens * wiki2text.py: Similar changes. Needs some more work.
Diffstat (limited to 'wiki2text.py')
-rw-r--r--wiki2text.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/wiki2text.py b/wiki2text.py
index c94ae51..3084ee4 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -144,2 +144,22 @@ class TextWikiMarkup (WikiMarkup):
+ supported_tags = [ 'nowiki', 'code' ]
+ def input_tag(self, tag):
+ return tag['tag'] in self.supported_tags
+
+ def str_tag(self, elt):
+ if elt['tag'] == 'nowiki':
+ return elt['content']
+ elif elt['tag'] == 'code':
+ kwdict = {
+ 'nested': self.nested + 1,
+ 'lang': self.lang,
+ 'text': elt['content'],
+ 'html_base': self.html_base,
+ 'image_base': self.image_base,
+ 'media_base': self.media_base }
+ markup = TextWiktionaryMarkup(**kwdict)
+ markup.debug_level = self.debug_level
+ markup.parse()
+ return str(markup)
+
def format(self, elt):
@@ -157,2 +177,7 @@ class TextWikiMarkup (WikiMarkup):
string = elt['content']
+ elif elt['type'] == 'PRE':
+ string = ""
+ for x in elt['content']:
+ string += self.format(x)
+ string += '\n'
elif elt['type'] == 'PARA':
@@ -162,2 +187,4 @@ class TextWikiMarkup (WikiMarkup):
string = self.fmtpara(string) + '\n\n'
+ elif elt['type'] == 'TAG':
+ string = self.str_tag(elt)
elif elt['type'] == 'IT':
@@ -216,3 +243,3 @@ class TextWikiMarkup (WikiMarkup):
elif type == "defn":
- if s[1] == 0:
+ if s['subtype'] == 0:
string += self.indent(lev-1, x)

Return to:

Send suggestions and report system problems to the System administrator.