# HG changeset patch # User Paul Boddie # Date 1370905906 -7200 # Node ID ef640bccabacebbeb54662da43db2d8b57c86f76 # Parent a79c3559e45c9beb52aeae7b74cfd20ed0c68cbe Attempted to fix list item identification, preventing items at the end of table rows from consuming the row end marker. Prevented the parsing and translation of "noformat" sections as normal markup. diff -r a79c3559e45c -r ef640bccabac wikiparser.py --- a/wikiparser.py Mon Jun 10 23:21:49 2013 +0200 +++ b/wikiparser.py Tue Jun 11 01:11:46 2013 +0200 @@ -45,9 +45,9 @@ r"|" \ r"(?P[|]{1,2}(\n|$))" \ r"|" \ - r"^(?P\s*[*#-]+\s+.*(\n|$))" + r"^(?P\s*[*#-]+\s+.*?([^|](\n|$)|(?=[|](\n|$))))" -sections_regexp = re.compile(sections_regexp_str, re.DOTALL | re.MULTILINE) +sections_regexp = re.compile(sections_regexp_str, re.MULTILINE) def get_regions(s): @@ -89,21 +89,30 @@ # table region. elif is_row: - if (last != start or not had_row): - regions.append(s[start:end]) - else: + if had_row and last == start: regions[-2] += regions[-1] + s[start:end] regions.pop() + else: + regions.append(s[start:end]) # A list item may either continue a list region or start a new # list region. elif is_item: - if (last != start or not had_item): - regions.append(s[start:end]) + + # If continuing a list, merge the list regions and start a + # new potentally separate region. + + if had_item and last == start: + regions[-2] += regions[-1] + s[start:end] + regions[-1] = "" + + # If not continuing a list, make a region for a new list and + # start a new potentally separate region. + else: - regions[-2] += regions[-1] + s[start:end] - regions.pop() + regions.append(s[start:end]) + regions.append("") # Certain markers may be standalone macros. @@ -119,7 +128,8 @@ if is_section or is_row: depth += 1 - # The end of a region is indicated by a marker with no options. + # The end of a region is indicated by a marker with no options or the + # end of a row. else: # Where no region is active, the text since the last match plus the @@ -662,7 +672,10 @@ # Sections can contain other sections. - section_content = self.parse_text(text.strip()) + if sectiontype == "noformat": + section_content = self.translate_content(text.strip("\n")) + else: + section_content = self.parse_text(text.strip()) # Nest the section appropriately.