1.1 --- a/MoinShare.py Wed Apr 18 01:12:13 2012 +0200
1.2 +++ b/MoinShare.py Wed Apr 18 01:13:25 2012 +0200
1.3 @@ -27,6 +27,8 @@
1.4 marker_regexp_str = r"([{]{3,}|[}]{3,})"
1.5 marker_regexp = re.compile(marker_regexp_str, re.MULTILINE | re.DOTALL) # {{{... or }}}...
1.6
1.7 +fragment_prelude = "#!MoinShare "
1.8 +
1.9 def getRegions(s):
1.10
1.11 "Parse the string 's', returning a list of shared regions."
1.12 @@ -72,4 +74,30 @@
1.13
1.14 return regions
1.15
1.16 +def getFragmentsFromRegions(regions):
1.17 +
1.18 + """
1.19 + Return fragments from the given 'regions', each having the form
1.20 + (arguments, body text).
1.21 + """
1.22 +
1.23 + fragments = []
1.24 +
1.25 + for region in regions:
1.26 + body = region.lstrip("{").rstrip("}")
1.27 + if body.startswith(fragment_prelude):
1.28 + arguments, body = body[len(fragment_prelude):].split("\n", 1)
1.29 + fragments.append((parseAttributes(arguments, False), body))
1.30 +
1.31 + return fragments
1.32 +
1.33 +def getFragments(s):
1.34 +
1.35 + """
1.36 + Return fragments for the given string 's', each having the form
1.37 + (arguments, body text).
1.38 + """
1.39 +
1.40 + return getFragmentsFromRegions(getRegions(s))
1.41 +
1.42 # vim: tabstop=4 expandtab shiftwidth=4