1.1 --- a/wikiparser.py Sun Jun 09 20:41:26 2013 +0200
1.2 +++ b/wikiparser.py Mon Jun 10 01:12:25 2013 +0200
1.3 @@ -28,7 +28,7 @@
1.4 2. Then, within these regions, the text is split into blocks.
1.5 1. First, lists are identified.
1.6 2. Additionally, other block-like elements are identified.
1.7 - 3. Each block is then parsed.
1.8 + 3. Each block is then split into regions.
1.9 """
1.10
1.11 from common import *
1.12 @@ -559,7 +559,7 @@
1.13 # Translate headings and blockquotes.
1.14
1.15 if blocktypes.has_key(blocktype):
1.16 - text = self.translate_content(blocktext)
1.17 + text = self.translate_content(self.parse_text(blocktext))
1.18 for anchor in self.held_anchors:
1.19 parts.append(anchor)
1.20 parts.append(blocktypes[blocktype] % text)
1.21 @@ -568,7 +568,7 @@
1.22
1.23 elif blocktype == "list":
1.24 for listmarker, listitem in get_list_items(blocktext):
1.25 - parts.append("%s %s" % (self.translate_marker(listmarker), self.translate_content(listitem)))
1.26 + parts.append("%s %s" % (self.translate_marker(listmarker), self.translate_content(self.parse_text(listitem))))
1.27
1.28 # Translate table items.
1.29
1.30 @@ -604,7 +604,7 @@
1.31 # Handle anonymous blocks.
1.32
1.33 else:
1.34 - parts.append(self.translate_content(blocktext))
1.35 + parts.append(self.translate_content(self.parse_text(blocktext)))
1.36
1.37 if blocktype in headings:
1.38 self.in_heading = False
1.39 @@ -679,6 +679,16 @@
1.40 # Handle list, heading, blockquote or anonymous blocks.
1.41
1.42 if type is None:
1.43 +
1.44 + # Where the region is the same as the provided text, return
1.45 + # immediately. This is the base case of the recursive parsing
1.46 + # process.
1.47 +
1.48 + if text == s:
1.49 + return text
1.50 +
1.51 + # Otherwise, obtain and translate the blocks.
1.52 +
1.53 if preceded_by_block:
1.54 parts.append("\n")
1.55
1.56 @@ -707,9 +717,13 @@
1.57 parts += self.translate_section(sectiontype, options, text)
1.58 preceded_by_block = True
1.59
1.60 - # Translations of macros (which can look like sections).
1.61 + # Translations of macros acting as sections.
1.62
1.63 elif macrotypes.has_key(sectiontype):
1.64 +
1.65 + # Prevent the production of macros in places they would
1.66 + # produce illegal Moin syntax.
1.67 +
1.68 if not self.forbids_macros():
1.69 self.macro = sectiontype
1.70 argname = macroargs.get(sectiontype)
1.71 @@ -718,6 +732,10 @@
1.72 "args" : quote_macro_argument((argname and ("%s=" % argname) or "") + options)
1.73 })
1.74 self.macro = None
1.75 +
1.76 + # Include the contents of section-based macros where the
1.77 + # macros themselves are not allowed.
1.78 +
1.79 else:
1.80 parts.append(self.translate_content(text))
1.81