# HG changeset patch # User Paul Boddie # Date 1298753156 -3600 # Node ID 5e3955c2714ba2964097db2142d5982887df5e7a # Parent 9e6baeb6ea5d9add1200a63af8176930fb6b93b0 Prevented category declarations from being moved from the end of a parent page into the final subpage. diff -r 9e6baeb6ea5d -r 5e3955c2714b MoinContentSupport.py --- a/MoinContentSupport.py Mon Feb 21 01:55:43 2011 +0100 +++ b/MoinContentSupport.py Sat Feb 26 21:45:56 2011 +0100 @@ -17,7 +17,10 @@ # NOTE: These overlap with ImprovedMoinSearch and EventAggregator. heading_regexp = re.compile(r"^(?P=+)\s*(?P.*?)\s*(?P=level)$", re.UNICODE | re.MULTILINE) -category_membership_regexp = re.compile(ur"^\s*(?:(Category\S+)(?:\s+(Category\S+))*)\s*$", re.MULTILINE | re.UNICODE) + +category_membership_str = ur"^\s*(?:(Category\S+)(?:\s+(Category\S+))*)\s*$" +category_membership_regexp = re.compile(category_membership_str, re.MULTILINE | re.UNICODE) +category_declarations_regexp = re.compile("^----$\s*" + category_membership_str, re.MULTILINE | re.UNICODE) def getHeadingDetails(body, min_level=None, max_level=None): @@ -52,7 +55,17 @@ else: return [] -def getCategoryDeclaration(categories): +def getCategoryDeclarations(body): + + """ + From the given 'body', return the category declaration sections in the page + in the form of a list of tuples, each containing a list of categories, the + start of the declaration region and the end of the region. + """ + + return [([x for x in match.groups() if x], match.span()) for match in category_declarations_regexp.finditer(body)] + +def makeCategoryDeclaration(categories): "Return a category declaration string for the given 'categories'." diff -r 9e6baeb6ea5d -r 5e3955c2714b actions/SectionBreakout.py --- a/actions/SectionBreakout.py Mon Feb 21 01:55:43 2011 +0100 +++ b/actions/SectionBreakout.py Sat Feb 26 21:45:56 2011 +0100 @@ -146,7 +146,18 @@ else: if current_region_start is not None: - regions.append(current_region_start + (len(page_body),)) + heading, region_start = current_region_start + + # Prevent any capture of end-of-page category information. + + l = getCategoryDeclarations(page_body) + if not l: + region_end = len(page_body) + else: + declaration, (start, end) = l[-1] + region_end = max(region_start, start) + + regions.append((heading, region_start, region_end)) # Make new pages for each region, rebuilding the current page body. @@ -180,7 +191,7 @@ # Add categories if the parent page has any. if new_page_categories != categories: - new_page_body += getCategoryDeclaration(categories) + new_page_body += makeCategoryDeclaration(categories) # Save the new page. @@ -218,7 +229,7 @@ # broken out. if edited_page_categories != categories: - edited_page_body += getCategoryDeclaration(categories) + edited_page_body += makeCategoryDeclaration(categories) # Save the current page.