diff options
| -rw-r--r-- | imagemap.py | 34 | ||||
| -rw-r--r-- | tests/data/refs/imagemap__--maptype__HTML__target__svg.out | 2 | ||||
| -rw-r--r-- | tests/data/svg/target.svg | 8 | ||||
| -rw-r--r-- | tests/test_imagemap_comparison.py | 1 |
4 files changed, 32 insertions, 13 deletions
diff --git a/imagemap.py b/imagemap.py index 9ab1e55..3595323 100644 --- a/imagemap.py +++ b/imagemap.py @@ -20,19 +20,24 @@ def htmlval(val): AREA_ATTRS={ 'href':lambda a:a.get('href',a.get('{http://www.w3.org/1999/xlink}href')), - 'alt':lambda a:a.get('aria-label',a.get('{http://www.w3.org/1999/xlink}title',a.title)) -} # TODO target + 'alt':lambda a:a.get('aria-label',a.get('{http://www.w3.org/1999/xlink}title',a.title)), + 'target': lambda a:a.get('target','_blank' if a.get('{http://www.w3.org/1999/xlink}show')=='new' else None), + 'download': lambda a:a.get('download'), + 'ping': lambda a:a.get('ping'), + 'rel': lambda a:a.get('rel'), + 'referrerpolicy': lambda a:a.get('referrerpolicy') +} SHAPE_MARKUP = { - 'HTML': lambda shape, coords, href, alt: - f"<area shape={shape} coords={','.join(str(c) for c in sum(coords,start=[]))}" - +(f' href{htmlval(href)}' if href is not None else '') - +(f' alt{htmlval(alt)}' if alt is not None else '')+">\n", - 'XHTML': lambda shape, coords, href, alt: - f"<area shape=\"{shape}\" coords=\"{','.join(str(c) for c in sum(coords,start=[]))}\"" - +(f" href={quotedval(href)}" if href is not None else '') - +(f' alt={quotedval(alt)}' if alt is not None else '')+"/>\n", - 'mod_imagemap': lambda shape, coords, href, alt: - f"{shape} {href if href is not None else 'nocontent'} {' '.join(f'{i[0]},{i[1]}' for i in coords)}" + 'HTML': lambda attrs: + f"<area shape={attrs['shape']} coords={','.join(str(c) for c in sum(attrs['coords'],start=[]))}" + +(''.join(f' {i}{htmlval(attrs[i])}' for i in attrs if attrs[i] is not None and i not in {'shape','coords'})) + +">\n", + 'XHTML': lambda attrs: + f"<area shape=\"{attrs['shape']}\" coords=\"{','.join(str(c) for c in sum(attrs['coords'],start=[]))}\"" + +(''.join(f" {i}={quotedval(attrs[i])}" for i in attrs if attrs[i] is not None and i not in {'shape','coords'})) + +"/>\n", + 'mod_imagemap': lambda attrs: + f"{attrs['shape']} {attrs['href'] or 'nocontent'} {' '.join(f'{i[0]},{i[1]}' for i in attrs['coords'])}" +(' "'+alt.translate({34:"''"})+'"' if alt is not None else '')+'\n' # no way to get quotation mark in text in httpd } # if we ever implement `circ` we gotta handle it specially CSS_LINK_INDEX='-computer-viatrix-inx-imagemap-linkindex' @@ -121,7 +126,10 @@ class ImageMap(inkex.OutputExtension): alt=links[i]['alt'] if len(shapes[i])==0: inkex.errormsg(_("The hyperlink \"{}\" is not present in the output.").format(links[i]['href'])) for j in shapes[i]: - stream.write(bytes(shapemarkup(j['shape'],j['coords'],j['href'],alt),'utf-8')) + attrs=links[i].copy() + attrs['alt']=alt + attrs.update(j) + stream.write(bytes(shapemarkup(attrs),'utf-8')) alt=None if __name__ == "__main__": diff --git a/tests/data/refs/imagemap__--maptype__HTML__target__svg.out b/tests/data/refs/imagemap__--maptype__HTML__target__svg.out new file mode 100644 index 0000000..e26d4d1 --- /dev/null +++ b/tests/data/refs/imagemap__--maptype__HTML__target__svg.out @@ -0,0 +1,2 @@ +<area shape=rect coords=25,25,75,75 href=http://example.com/1 target=_top> +<area shape=rect coords=125,25,175,75 href=http://example.com/2 target=_blank> diff --git a/tests/data/svg/target.svg b/tests/data/svg/target.svg new file mode 100644 index 0000000..ed54e7c --- /dev/null +++ b/tests/data/svg/target.svg @@ -0,0 +1,8 @@ +<svg width="200" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + <a xlink:href="http://example.com/1" target="_top"> + <rect x="25" y="25" width="50" height="50"/> + </a> + <a xlink:href="http://example.com/2" xlink:show="new"> + <rect x="125" y="25" width="50" height="50"/> + </a> +</svg> diff --git a/tests/test_imagemap_comparison.py b/tests/test_imagemap_comparison.py index b4fae16..4b734b8 100644 --- a/tests/test_imagemap_comparison.py +++ b/tests/test_imagemap_comparison.py @@ -13,6 +13,7 @@ class ImageMapComparisonTest(ComparisonMixin, TestCase): 'svg/oob.svg', 'svg/overlap.svg', 'svg/rounding.svg', + 'svg/target.svg', 'svg/text.svg', 'svg/transform.svg', 'svg/viewbox.svg' |
