(11.269322, 47.113421, None, None),
(11.269979, 47.11277, None, None),
(11.271119, 47.112408, None, None)])]
+ center, zoom, coords, paths, start, end = wrpylib.mwmarkup.parse_googlemap(wikitext, detail=True)
+ assert start == 5
+ assert end == 344
+ result = wrpylib.mwmarkup.parse_googlemap(wikitext.replace('<googlemap', '|googlemap'), detail=True)
+ assert result is None
+
return pipe_char.join(parts) + end_char
-def parse_googlemap(wikitext):
+def parse_googlemap(wikitext, detail=False):
"""Parses the (unicode) u'<googlemap ...>content</googlemap>' of the googlemap extension
out of a page. If wikitext does not contain the googlemaps extension text None is returned.
If the googlemap contains invalid formatted lines, a RuntimeError is raised.
:param wikitext: wikitext containing the template. Example:
+ :param detail: bool. If True, start and end position of <googlemaps>...</googlemap> is
+ returned additionally.
wikitext = '''
<googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15">
zoom is the google zoom level as integer or None if not provided
coords is a list of (lon, lat, symbol, title) tuples.
paths is a list of (style, coords) tuples.
- coords is again a list of (lot, lat, symbol, title) tuples."""
+ coords is again a list of (lot, lat, symbol, title) tuples.
+ If detail is True, (center, zoom, coords, paths, start, end) is returned."""
def is_coord(line):
"""Returns True if the line contains a coordinate."""
regexp = re.compile(u"(<googlemap[^>]*>)(.*)(</googlemap>)", re.DOTALL)
match = regexp.search(wikitext)
if match is None: return None
+ start = match.start()
+ end = match.end()
content = match.group(2)
gm = xml.etree.ElementTree.XML((match.group(1)+match.group(3)).encode('UTF8'))
zoom = gm.get('zoom')
continue
raise RuntimeError(u'Unknown line syntax: ' + line)
+ if detail:
+ return (center, zoom, coords, paths, start, end)
return (center, zoom, coords, paths)