summaryrefslogtreecommitdiff
path: root/wiki2html.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 /wiki2html.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 'wiki2html.py')
-rw-r--r--wiki2html.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/wiki2html.py b/wiki2html.py
index eee592d..061377b 100644
--- a/wiki2html.py
+++ b/wiki2html.py
@@ -172,12 +172,38 @@ class HtmlWikiMarkup (WikiMarkup):
self.envt[type]["hdr"])
return string
+ 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 '<pre>' + elt['content'] + '</pre>'
+ 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 = HtmlWiktionaryMarkup(**kwdict)
+ markup.debug_level = self.debug_level
+ markup.parse()
+ return '<pre><code>' + str(markup) + '</code></pre>' #FIXME
+
def str_para(self, elt):
string = "";
for x in elt['content']:
string += self.format(x)
return "<p>" + string + "</p>"
+ def str_pre(self, elt):
+ string = "";
+ for x in elt['content']:
+ string += self.format(x)
+ return '<pre>' + string + '</pre>'
+
def str_ind(self, elt):
return ("&nbsp;" * 2 * elt['level']) + self.format(elt['content'])
@@ -190,8 +216,12 @@ class HtmlWikiMarkup (WikiMarkup):
else:
string = elt['content']
return string
+ elif elt['type'] == 'TAG':
+ return self.str_tag(elt)
elif elt['type'] == 'PARA':
return self.str_para(elt)
+ elif elt['type'] == 'PRE':
+ return self.str_pre(elt)
elif elt['type'] == 'IT':
return self.str_it(elt)
elif elt['type'] == 'BOLD':

Return to:

Send suggestions and report system problems to the System administrator.