aboutsummaryrefslogtreecommitdiff
path: root/imagemap.py
diff options
context:
space:
mode:
authorViatrix2026-03-15 20:50:07 -0700
committerViatrix2026-03-15 20:50:07 -0700
commitfbcbb4eff55d0703f9fee526e5caea4744e931f7 (patch)
treecbf246a465fda28f39e4f04e8032ac639dcc9de6 /imagemap.py
parent57aa116144d51783a12bb288554dd69846706386 (diff)
Target attribute (and others) now work.
Diffstat (limited to 'imagemap.py')
-rw-r--r--imagemap.py34
1 files changed, 21 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__":