1.1 --- a/tests/test_lists.txt Mon Jun 10 18:52:25 2013 +0200
1.2 +++ b/tests/test_lists.txt Mon Jun 10 23:21:49 2013 +0200
1.3 @@ -2,4 +2,5 @@
1.4 * First item
1.5 * Second item
1.6 ** Sublist item
1.7 + ** Item in {color:#00ff00}colour{color}
1.8 * Final item
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/test_tables_lists_macros.txt Mon Jun 10 23:21:49 2013 +0200
2.3 @@ -0,0 +1,9 @@
2.4 +A table:
2.5 +
2.6 +|| Heading || Heading ||
2.7 +| Cell | Cell with list:
2.8 +* {color:#ff0000}Red{color}
2.9 +* {color:#00ff00}Green{color}
2.10 +* {color:#0000ff}Blue{color} |
2.11 +
2.12 +After the table.
3.1 --- a/wikiparser.py Mon Jun 10 18:52:25 2013 +0200
3.2 +++ b/wikiparser.py Mon Jun 10 23:21:49 2013 +0200
3.3 @@ -39,7 +39,14 @@
3.4
3.5 # Section extraction.
3.6
3.7 -sections_regexp_str = r"(?<!{){(?P<type>[^-_*+{}\n:]+)(?P<options>:[^}\n]+)?}|^(?P<rowstart>[|]{1,2})|(?P<rowend>[|]{1,2})(\n|$)"
3.8 +sections_regexp_str = r"(?<!{){(?P<type>[^-_*+{}\n:]+)(?P<options>:[^}\n]+)?}" \
3.9 + r"|" \
3.10 + r"^(?P<rowstart>[|]{1,2})" \
3.11 + r"|" \
3.12 + r"(?P<rowend>[|]{1,2}(\n|$))" \
3.13 + r"|" \
3.14 + r"^(?P<listitem>\s*[*#-]+\s+.*(\n|$))"
3.15 +
3.16 sections_regexp = re.compile(sections_regexp_str, re.DOTALL | re.MULTILINE)
3.17
3.18 def get_regions(s):
3.19 @@ -53,12 +60,14 @@
3.20 regions = [""]
3.21 depth = 0
3.22 had_row = False
3.23 + had_item = False
3.24
3.25 for match in sections_regexp.finditer(s):
3.26 start, end = match.span()
3.27 is_start = match.group("options") or match.group("rowstart")
3.28 is_section = is_section_marker(match.group("type"))
3.29 is_row = match.group("rowstart") or match.group("rowend")
3.30 + is_item = match.group("listitem")
3.31
3.32 # The start of a region is either indicated by a marker with options or
3.33 # by a marker where no region is currently active.
3.34 @@ -86,6 +95,16 @@
3.35 regions[-2] += regions[-1] + s[start:end]
3.36 regions.pop()
3.37
3.38 + # A list item may either continue a list region or start a new
3.39 + # list region.
3.40 +
3.41 + elif is_item:
3.42 + if (last != start or not had_item):
3.43 + regions.append(s[start:end])
3.44 + else:
3.45 + regions[-2] += regions[-1] + s[start:end]
3.46 + regions.pop()
3.47 +
3.48 # Certain markers may be standalone macros.
3.49
3.50 else:
3.51 @@ -131,6 +150,7 @@
3.52 depth -= 1
3.53
3.54 had_row = is_row
3.55 + had_item = is_item
3.56 last = end
3.57
3.58 # Where a region is still active, terminate it.