# HG changeset patch # User Paul Boddie # Date 1370821611 -7200 # Node ID fb2a594422b390e3f3ebe71161d14abc864dcf5d # Parent 1f3781d8fda5f425ff332c1a098b952cddde1c62 Fixed the translation when only one region exists. Tidied up usage of translate_content and parse_text. diff -r 1f3781d8fda5 -r fb2a594422b3 wikiparser.py --- a/wikiparser.py Mon Jun 10 01:18:49 2013 +0200 +++ b/wikiparser.py Mon Jun 10 01:46:51 2013 +0200 @@ -559,7 +559,7 @@ # Translate headings and blockquotes. if blocktypes.has_key(blocktype): - text = self.translate_content(self.parse_text(blocktext)) + text = self.parse_text(blocktext) for anchor in self.held_anchors: parts.append(anchor) parts.append(blocktypes[blocktype] % text) @@ -568,7 +568,7 @@ elif blocktype == "list": for listmarker, listitem in get_list_items(blocktext): - parts.append("%s %s" % (self.translate_marker(listmarker), self.translate_content(self.parse_text(listitem)))) + parts.append("%s %s" % (self.translate_marker(listmarker), self.parse_text(listitem))) # Translate table items. @@ -604,7 +604,7 @@ # Handle anonymous blocks. else: - parts.append(self.translate_content(self.parse_text(blocktext))) + parts.append(self.parse_text(blocktext)) if blocktype in headings: self.in_heading = False @@ -664,7 +664,7 @@ # General parsing. - def parse_text(self, s): + def parse_text(self, s, top=False): "Parse the content in the string 's', returning the translation." @@ -684,8 +684,8 @@ # immediately. This is the base case of the recursive parsing # process. - if text == s: - return text + if text == s and not top: + return self.translate_content(text) # Otherwise, obtain and translate the blocks. @@ -757,7 +757,7 @@ "Parse the content in the string 's', writing a translation to 'out'." parser = ConfluenceParser() - out.write(parser.parse_text(s)) + out.write(parser.parse_text(s, top=True)) if __name__ == "__main__": s = codecs.getreader("utf-8")(sys.stdin).read()