# HG changeset patch # User Paul Boddie # Date 1286117560 -7200 # Node ID a19b22ba78ce97b486796c62549ed32d10ab5077 # Parent b9d34861708c6557f4a8755e7bce60f9110841fd Introduced specific linking of formatted data. diff -r b9d34861708c -r a19b22ba78ce ImprovedMoinSearch.py --- a/ImprovedMoinSearch.py Sun Sep 26 22:22:16 2010 +0200 +++ b/ImprovedMoinSearch.py Sun Oct 03 16:52:40 2010 +0200 @@ -17,11 +17,15 @@ def range_groups(min_name, max_name): return r"(?P<%s>-?\d+)?(?:\s*-\s*(?P<%s>-?\d+))?" % (min_name, max_name) -format_options_regexp = re.compile(r"(" - "(?P(heading|title|h)\s*" + range_groups("min_heading", "max_heading") + ")" - "|(?P(paragraph|para|p)\s*(?P\d+)?)" - "|(?P(name|page)\s*" + range_groups("first", "last") + ")" - ")", re.UNICODE) +format_options_regexp = re.compile( + r"(?P\[)?" + r"(" + r"(?P(heading|title|h)\s*" + range_groups("min_heading", "max_heading") + ")" + r"|(?P(paragraph|para|p)\s*(?P\d+)?)" + r"|(?P(name|page)\s*" + range_groups("first", "last") + ")" + r")" + r"(?(link)\]|)", + re.UNICODE) def convert_index(i, length): @@ -146,14 +150,15 @@ if format: for match in format_options_regexp.finditer(format): + as_link = match.group("link") if match.group("heading"): - actions.append((getFirstPageHeading, map(int_or_none, (match.group("min_heading"), match.group("max_heading"))))) + actions.append((getFirstPageHeading, map(int_or_none, (match.group("min_heading"), match.group("max_heading"))), as_link)) elif match.group("paragraph"): - actions.append((getParagraph, map(int_or_none, (match.group("paragraph_number"),)))) + actions.append((getParagraph, map(int_or_none, (match.group("paragraph_number"),)), as_link)) elif match.group("name"): - actions.append((getPageName, map(int_or_none, (match.group("first"), match.group("last"))))) + actions.append((getPageName, map(int_or_none, (match.group("first"), match.group("last"))), as_link)) else: - actions.append((getPageName, ())) + actions.append((getPageName, (), True)) # Use paging only when there are enough results. @@ -175,14 +180,14 @@ start = 0 first = 1 - for action, args in actions: + for action, args, as_link in actions: result = action(request, page, start, *args) if result is not None: - if first: + if not first: + output.append(" ") + if as_link: output.append(formatter.pagelink(on=1, pagename=page.page_name)) - else: - output.append(" ") text, span = result output.append(formatter.text(text)) @@ -192,7 +197,7 @@ _start, _end = span start = _end + 1 - if first: + if as_link: output.append(formatter.pagelink(on=0)) first = 0