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 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
(limited to 'imagemap.py')
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__":
--
cgit