From fbcbb4eff55d0703f9fee526e5caea4744e931f7 Mon Sep 17 00:00:00 2001
From: Viatrix
Date: Sun, 15 Mar 2026 20:50:07 -0700
Subject: Target attribute (and others) now work.
---
imagemap.py | 34 +++++++++++++---------
.../imagemap__--maptype__HTML__target__svg.out | 2 ++
tests/data/svg/target.svg | 8 +++++
tests/test_imagemap_comparison.py | 1 +
4 files changed, 32 insertions(+), 13 deletions(-)
create mode 100644 tests/data/refs/imagemap__--maptype__HTML__target__svg.out
create mode 100644 tests/data/svg/target.svg
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"\n",
- 'XHTML': lambda shape, coords, href, alt:
- f"\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"\n",
+ 'XHTML': lambda attrs:
+ f"\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 @@
+
+
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 @@
+
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'
--
cgit