1.1 --- a/MoinContentSupport.py Mon Oct 04 01:03:07 2010 +0200
1.2 +++ b/MoinContentSupport.py Sun Feb 20 21:15:05 2011 +0100
1.3 @@ -2,14 +2,45 @@
1.4 """
1.5 MoinMoin - MoinContentSupport library
1.6
1.7 - @copyright: 2008, 2009, 2010 by Paul Boddie <paul@boddie.org.uk>
1.8 + @copyright: 2008, 2009, 2010, 2011 by Paul Boddie <paul@boddie.org.uk>
1.9 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
1.10 2005-2008 MoinMoin:ThomasWaldmann.
1.11 @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.12 """
1.13
1.14 +from MoinMoin.wikiutil import escape
1.15 +import re
1.16 +
1.17 __version__ = "0.1"
1.18
1.19 +# Regular expressions.
1.20 +# NOTE: These overlap with ImprovedMoinSearch.
1.21 +
1.22 +heading_regexp = re.compile(r"^(?P<level>=+)\s*(?P<heading>.*?)\s*(?P=level)$", re.UNICODE | re.MULTILINE)
1.23 +
1.24 +def getHeadingDetails(body, min_level=None, max_level=None):
1.25 +
1.26 + """
1.27 + Return heading details from the given 'body' for headings with the given
1.28 + 'min_level' to 'max_level' range. Specifying None or omitting 'max_level' or
1.29 + 'min_level' removes the appropriate constraint on the range.
1.30 +
1.31 + A list of tuples containing the heading, the level, and the span (the start
1.32 + offset and the end offset as a tuple) is returned.
1.33 + """
1.34 +
1.35 + headings = []
1.36 +
1.37 + for match in heading_regexp.finditer(body):
1.38 + level = len(match.group("level"))
1.39 +
1.40 + if (min_level is None or min_level <= level) and \
1.41 + (max_level is None or level <= max_level):
1.42 +
1.43 + headings.append((match.group("heading"), level, match.span()))
1.44 +
1.45 + return headings
1.46 +
1.47 # Utility classes and associated functions.
1.48 # NOTE: These are a subset of EventAggregatorSupport.
1.49
1.50 @@ -67,4 +98,7 @@
1.51 parts = header.split(":")
1.52 self.request.headers.add(parts[0], ":".join(parts[1:]))
1.53
1.54 +def escattr(s):
1.55 + return escape(s, 1)
1.56 +
1.57 # vim: tabstop=4 expandtab shiftwidth=4