1.1 --- a/MoinContentSupport.py Mon Feb 21 01:55:43 2011 +0100
1.2 +++ b/MoinContentSupport.py Sat Feb 26 21:45:56 2011 +0100
1.3 @@ -17,7 +17,10 @@
1.4 # NOTE: These overlap with ImprovedMoinSearch and EventAggregator.
1.5
1.6 heading_regexp = re.compile(r"^(?P<level>=+)\s*(?P<heading>.*?)\s*(?P=level)$", re.UNICODE | re.MULTILINE)
1.7 -category_membership_regexp = re.compile(ur"^\s*(?:(Category\S+)(?:\s+(Category\S+))*)\s*$", re.MULTILINE | re.UNICODE)
1.8 +
1.9 +category_membership_str = ur"^\s*(?:(Category\S+)(?:\s+(Category\S+))*)\s*$"
1.10 +category_membership_regexp = re.compile(category_membership_str, re.MULTILINE | re.UNICODE)
1.11 +category_declarations_regexp = re.compile("^----$\s*" + category_membership_str, re.MULTILINE | re.UNICODE)
1.12
1.13 def getHeadingDetails(body, min_level=None, max_level=None):
1.14
1.15 @@ -52,7 +55,17 @@
1.16 else:
1.17 return []
1.18
1.19 -def getCategoryDeclaration(categories):
1.20 +def getCategoryDeclarations(body):
1.21 +
1.22 + """
1.23 + From the given 'body', return the category declaration sections in the page
1.24 + in the form of a list of tuples, each containing a list of categories, the
1.25 + start of the declaration region and the end of the region.
1.26 + """
1.27 +
1.28 + return [([x for x in match.groups() if x], match.span()) for match in category_declarations_regexp.finditer(body)]
1.29 +
1.30 +def makeCategoryDeclaration(categories):
1.31
1.32 "Return a category declaration string for the given 'categories'."
1.33
2.1 --- a/actions/SectionBreakout.py Mon Feb 21 01:55:43 2011 +0100
2.2 +++ b/actions/SectionBreakout.py Sat Feb 26 21:45:56 2011 +0100
2.3 @@ -146,7 +146,18 @@
2.4
2.5 else:
2.6 if current_region_start is not None:
2.7 - regions.append(current_region_start + (len(page_body),))
2.8 + heading, region_start = current_region_start
2.9 +
2.10 + # Prevent any capture of end-of-page category information.
2.11 +
2.12 + l = getCategoryDeclarations(page_body)
2.13 + if not l:
2.14 + region_end = len(page_body)
2.15 + else:
2.16 + declaration, (start, end) = l[-1]
2.17 + region_end = max(region_start, start)
2.18 +
2.19 + regions.append((heading, region_start, region_end))
2.20
2.21 # Make new pages for each region, rebuilding the current page body.
2.22
2.23 @@ -180,7 +191,7 @@
2.24 # Add categories if the parent page has any.
2.25
2.26 if new_page_categories != categories:
2.27 - new_page_body += getCategoryDeclaration(categories)
2.28 + new_page_body += makeCategoryDeclaration(categories)
2.29
2.30 # Save the new page.
2.31
2.32 @@ -218,7 +229,7 @@
2.33 # broken out.
2.34
2.35 if edited_page_categories != categories:
2.36 - edited_page_body += getCategoryDeclaration(categories)
2.37 + edited_page_body += makeCategoryDeclaration(categories)
2.38
2.39 # Save the current page.
2.40