1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/test_macros_nested.txt Sun Jun 09 19:53:44 2013 +0200
1.3 @@ -0,0 +1,1 @@
1.4 +Really {color:#003366}nasty {color:#003366}nested{color} text{color}.
2.1 --- a/wikiparser.py Sun Jun 09 19:44:41 2013 +0200
2.2 +++ b/wikiparser.py Sun Jun 09 19:53:44 2013 +0200
2.3 @@ -38,7 +38,7 @@
2.4
2.5 # Section extraction.
2.6
2.7 -sections_regexp_str = r"(?<!{){(?P<type>[^-_*+{}\n:]+)(:[^}\n]+)?}.*?{(?P=type)}"
2.8 +sections_regexp_str = r"(?<!{){(?P<type>[^-_*+{}\n:]+)(?P<options>:[^}\n]+)?}"
2.9 sections_regexp = re.compile(sections_regexp_str, re.DOTALL | re.MULTILINE)
2.10
2.11 def get_regions(s):
2.12 @@ -50,12 +50,77 @@
2.13
2.14 last = 0
2.15 regions = []
2.16 + depth = 0
2.17 +
2.18 for match in sections_regexp.finditer(s):
2.19 start, end = match.span()
2.20 - regions.append((None, s[last:start]))
2.21 - regions.append(get_section_details(s[start:end]))
2.22 + is_start = match.group("options")
2.23 +
2.24 + # The start of a region is either indicated by a marker with options or
2.25 + # by a marker where no region is currently active.
2.26 +
2.27 + if is_start or not depth:
2.28 +
2.29 + # Where no region is active, add the text since the last match as a
2.30 + # "null" region.
2.31 +
2.32 + if not depth:
2.33 + regions.append((None, s[last:start]))
2.34 +
2.35 + # A new region is maintained as a string.
2.36 +
2.37 + regions.append(s[start:end])
2.38 +
2.39 + # Where a region is active, add the text since the last match as
2.40 + # well as the text in this match to the region.
2.41 +
2.42 + else:
2.43 + regions[-1] += s[last:end]
2.44 +
2.45 + # Any start marker will cause an increase in the depth of the region
2.46 + # nesting.
2.47 +
2.48 + depth += 1
2.49 +
2.50 + # The end of a region is indicated by a marker with no options.
2.51 +
2.52 + else:
2.53 + # Where no region is active, the text since the last match plus the
2.54 + # marker are added to the current "null" region.
2.55 +
2.56 + if not depth:
2.57 +
2.58 + # Add to the string portion of the "null" region.
2.59 +
2.60 + regions[-1][1] += s[last:end]
2.61 +
2.62 + # Where a region is active, the end marker and preceding text is
2.63 + # either incorporated into the current region if more than one
2.64 + # region is active, or the preceding text is incorporated into the
2.65 + # current region and the details of the region are then obtained.
2.66 +
2.67 + else:
2.68 + if depth > 1:
2.69 + regions[-1] += s[last:end]
2.70 +
2.71 + # Terminate the active region, interpreting its contents.
2.72 +
2.73 + else:
2.74 + regions[-1] = get_section_details(regions[-1] + s[last:end])
2.75 + depth -= 1
2.76 +
2.77 last = end
2.78 - regions.append((None, s[last:]))
2.79 +
2.80 + # Where a region is still active, terminate it.
2.81 +
2.82 + if depth:
2.83 + regions[-1] = get_section_details(regions[-1] + s[last:])
2.84 +
2.85 + # Otherwise, add a "null" region.
2.86 +
2.87 + else:
2.88 + regions.append((None, s[last:]))
2.89 +
2.90 return regions
2.91
2.92 # Section inspection.
2.93 @@ -632,7 +697,7 @@
2.94 elif macrotypes.has_key(sectiontype) and not self.forbids_macros():
2.95 argname = macroargs.get(sectiontype)
2.96 parts.append(macrotypes[sectiontype] % {
2.97 - "content" : quote_macro_argument(self.translate_content(text, sectiontype)),
2.98 + "content" : quote_macro_argument(self.parse_text(text)),
2.99 "args" : quote_macro_argument((argname and ("%s=" % argname) or "") + options)
2.100 })
2.101 preceded_by_block = False