summaryrefslogtreecommitdiffabout
path: root/wiki2text.py
authorSergey Poznyakoff <gray@gnu.org.ua>2015-07-06 14:01:23 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2015-07-06 14:36:49 (GMT)
commitb74b1d5fe2326f56a2e37f57c38b929307c71282 (patch) (side-by-side diff)
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') (more/less context) (ignore whitespace changes)
-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
@@ -142,6 +142,26 @@ class TextWikiMarkup (WikiMarkup):
length += wsc + wlen
return output + linebuf
+ 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):
if elt['type'] == 'TEXT':
if isinstance(elt['content'],list):
@@ -155,11 +175,18 @@ class TextWikiMarkup (WikiMarkup):
string += s
else:
string = elt['content']
+ elif elt['type'] == 'PRE':
+ string = ""
+ for x in elt['content']:
+ string += self.format(x)
+ string += '\n'
elif elt['type'] == 'PARA':
string = "";
for x in elt['content']:
string += self.format(x)
string = self.fmtpara(string) + '\n\n'
+ elif elt['type'] == 'TAG':
+ string = self.str_tag(elt)
elif elt['type'] == 'IT':
string = ""
for x in elt['content']:
@@ -214,7 +241,7 @@ class TextWikiMarkup (WikiMarkup):
string += self.fmtpara(self.indent(lev, "%d. %s" % (n, x)))
n += 1
elif type == "defn":
- if s[1] == 0:
+ if s['subtype'] == 0:
string += self.indent(lev-1, x)
else:
string += self.indent(lev+3, x)

Return to:

Send suggestions and report system problems to the System administrator.