1.1 --- a/wikiparser.py Mon Jun 10 23:21:49 2013 +0200
1.2 +++ b/wikiparser.py Tue Jun 11 01:11:46 2013 +0200
1.3 @@ -45,9 +45,9 @@
1.4 r"|" \
1.5 r"(?P<rowend>[|]{1,2}(\n|$))" \
1.6 r"|" \
1.7 - r"^(?P<listitem>\s*[*#-]+\s+.*(\n|$))"
1.8 + r"^(?P<listitem>\s*[*#-]+\s+.*?([^|](\n|$)|(?=[|](\n|$))))"
1.9
1.10 -sections_regexp = re.compile(sections_regexp_str, re.DOTALL | re.MULTILINE)
1.11 +sections_regexp = re.compile(sections_regexp_str, re.MULTILINE)
1.12
1.13 def get_regions(s):
1.14
1.15 @@ -89,21 +89,30 @@
1.16 # table region.
1.17
1.18 elif is_row:
1.19 - if (last != start or not had_row):
1.20 - regions.append(s[start:end])
1.21 - else:
1.22 + if had_row and last == start:
1.23 regions[-2] += regions[-1] + s[start:end]
1.24 regions.pop()
1.25 + else:
1.26 + regions.append(s[start:end])
1.27
1.28 # A list item may either continue a list region or start a new
1.29 # list region.
1.30
1.31 elif is_item:
1.32 - if (last != start or not had_item):
1.33 - regions.append(s[start:end])
1.34 +
1.35 + # If continuing a list, merge the list regions and start a
1.36 + # new potentally separate region.
1.37 +
1.38 + if had_item and last == start:
1.39 + regions[-2] += regions[-1] + s[start:end]
1.40 + regions[-1] = ""
1.41 +
1.42 + # If not continuing a list, make a region for a new list and
1.43 + # start a new potentally separate region.
1.44 +
1.45 else:
1.46 - regions[-2] += regions[-1] + s[start:end]
1.47 - regions.pop()
1.48 + regions.append(s[start:end])
1.49 + regions.append("")
1.50
1.51 # Certain markers may be standalone macros.
1.52
1.53 @@ -119,7 +128,8 @@
1.54 if is_section or is_row:
1.55 depth += 1
1.56
1.57 - # The end of a region is indicated by a marker with no options.
1.58 + # The end of a region is indicated by a marker with no options or the
1.59 + # end of a row.
1.60
1.61 else:
1.62 # Where no region is active, the text since the last match plus the
1.63 @@ -662,7 +672,10 @@
1.64
1.65 # Sections can contain other sections.
1.66
1.67 - section_content = self.parse_text(text.strip())
1.68 + if sectiontype == "noformat":
1.69 + section_content = self.translate_content(text.strip("\n"))
1.70 + else:
1.71 + section_content = self.parse_text(text.strip())
1.72
1.73 # Nest the section appropriately.
1.74