# HG changeset patch # User Paul Boddie # Date 1353621870 -3600 # Node ID 42877c4c7e0245673a538a23b449cbcb17e3d9f3 # Parent 53fa1f193ebbf90b6a89e095224e5b09e446dd78 Added support for title extraction from headings in special event regions and formatting titles as headings when showing event regions. diff -r 53fa1f193ebb -r 42877c4c7e02 EventAggregatorSupport.py --- a/EventAggregatorSupport.py Sun Nov 18 21:16:00 2012 +0100 +++ b/EventAggregatorSupport.py Thu Nov 22 23:04:30 2012 +0100 @@ -141,6 +141,9 @@ Parse events in the given 'text', returning a list of event objects for the given 'event_page'. An optional 'fragment' can be specified to indicate a specific region of the event page. + + If the optional 'fragment' identifier is provided, the first heading may + also be used to provide an event summary/title. """ template_details = {} @@ -150,6 +153,17 @@ details = {} details.update(template_details) raw_details = {} + + # Obtain a heading, if requested. + + if fragment: + for level, title, (start, end) in getHeadings(text): + raw_details["title"] = text[start:end] + details["title"] = getSimpleWikiText(title.strip()) + break + + # Start populating events. + events = [Event(event_page, details, raw_details)] for match in definition_list_regexp.finditer(text): @@ -3266,9 +3280,22 @@ if details.has_key("fragment"): write(fmt.anchordef(details["fragment"])) + # Promote any title to a heading above the event details. + + if raw_details.has_key("title"): + write(formatText(raw_details["title"], request, fmt)) + elif details.has_key("title"): + write(fmt.heading(on=1, depth=1)) + write(fmt.text(details["title"])) + write(fmt.heading(on=0, depth=1)) + + # Produce a definition list for the rest of the details. + write(fmt.definition_list(on=1)) for term in event.all_terms: + if term == "title": + continue raw_value = raw_details.get(term) value = details.get(term)