# HG changeset patch # User Paul Boddie # Date 1339883789 -7200 # Node ID fbc23cb12279288a1ab741e766d7590f4a34b2d9 # Parent 8de8a75d3bacc73c57ec4dd54959a26be1b51e13 Detect and return the format of fragments. diff -r 8de8a75d3bac -r fbc23cb12279 MoinShare.py --- a/MoinShare.py Sat Jun 16 20:33:46 2012 +0200 +++ b/MoinShare.py Sat Jun 16 23:56:29 2012 +0200 @@ -81,18 +81,38 @@ """ Return fragments from the given 'regions', each having the form - (arguments, body text). + (format, arguments, body text). """ fragments = [] for region in regions: - body = region.lstrip("{").rstrip("}") + body = region.lstrip("{").rstrip("}").lstrip() if body.startswith(fragment_prelude): arguments, body = body[len(fragment_prelude):].split("\n", 1) + + # Get any parser/format declaration. + + if arguments and not arguments[0].isspace(): + format, arguments = arguments.split(None, 1) + else: + format = None + + # Get the attributes/arguments for the region. + attributes = parseAttributes(arguments, False) + + # If the format is the MoinShare attribute, move it into the + # dictionary. + + if format.lower() == fragment_attribute: + attributes[fragment_attribute] = True + format = None + + # Only collect appropriate regions. + if attributes.has_key(fragment_attribute): - fragments.append((attributes, body)) + fragments.append((format, attributes, body)) return fragments