1.1 --- a/ImprovedMoinSearch.py Sun Sep 26 22:22:16 2010 +0200
1.2 +++ b/ImprovedMoinSearch.py Sun Oct 03 16:52:40 2010 +0200
1.3 @@ -17,11 +17,15 @@
1.4 def range_groups(min_name, max_name):
1.5 return r"(?P<%s>-?\d+)?(?:\s*-\s*(?P<%s>-?\d+))?" % (min_name, max_name)
1.6
1.7 -format_options_regexp = re.compile(r"("
1.8 - "(?P<heading>(heading|title|h)\s*" + range_groups("min_heading", "max_heading") + ")"
1.9 - "|(?P<paragraph>(paragraph|para|p)\s*(?P<paragraph_number>\d+)?)"
1.10 - "|(?P<name>(name|page)\s*" + range_groups("first", "last") + ")"
1.11 - ")", re.UNICODE)
1.12 +format_options_regexp = re.compile(
1.13 + r"(?P<link>\[)?"
1.14 + r"("
1.15 + r"(?P<heading>(heading|title|h)\s*" + range_groups("min_heading", "max_heading") + ")"
1.16 + r"|(?P<paragraph>(paragraph|para|p)\s*(?P<paragraph_number>\d+)?)"
1.17 + r"|(?P<name>(name|page)\s*" + range_groups("first", "last") + ")"
1.18 + r")"
1.19 + r"(?(link)\]|)",
1.20 + re.UNICODE)
1.21
1.22 def convert_index(i, length):
1.23
1.24 @@ -146,14 +150,15 @@
1.25
1.26 if format:
1.27 for match in format_options_regexp.finditer(format):
1.28 + as_link = match.group("link")
1.29 if match.group("heading"):
1.30 - actions.append((getFirstPageHeading, map(int_or_none, (match.group("min_heading"), match.group("max_heading")))))
1.31 + actions.append((getFirstPageHeading, map(int_or_none, (match.group("min_heading"), match.group("max_heading"))), as_link))
1.32 elif match.group("paragraph"):
1.33 - actions.append((getParagraph, map(int_or_none, (match.group("paragraph_number"),))))
1.34 + actions.append((getParagraph, map(int_or_none, (match.group("paragraph_number"),)), as_link))
1.35 elif match.group("name"):
1.36 - actions.append((getPageName, map(int_or_none, (match.group("first"), match.group("last")))))
1.37 + actions.append((getPageName, map(int_or_none, (match.group("first"), match.group("last"))), as_link))
1.38 else:
1.39 - actions.append((getPageName, ()))
1.40 + actions.append((getPageName, (), True))
1.41
1.42 # Use paging only when there are enough results.
1.43
1.44 @@ -175,14 +180,14 @@
1.45
1.46 start = 0
1.47 first = 1
1.48 - for action, args in actions:
1.49 + for action, args, as_link in actions:
1.50 result = action(request, page, start, *args)
1.51
1.52 if result is not None:
1.53 - if first:
1.54 + if not first:
1.55 + output.append(" ")
1.56 + if as_link:
1.57 output.append(formatter.pagelink(on=1, pagename=page.page_name))
1.58 - else:
1.59 - output.append(" ")
1.60
1.61 text, span = result
1.62 output.append(formatter.text(text))
1.63 @@ -192,7 +197,7 @@
1.64 _start, _end = span
1.65 start = _end + 1
1.66
1.67 - if first:
1.68 + if as_link:
1.69 output.append(formatter.pagelink(on=0))
1.70
1.71 first = 0