aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViatrix2026-03-18 16:45:27 -0700
committerViatrix2026-03-18 16:45:27 -0700
commitdfe3e6410b3592744a3041e2d90ce856e1c592c6 (patch)
treee0e615547090370fd592e9f1f8210ec82dee61f4
parent274ad4460f3f4a35e099545a1a8408a9a67614e1 (diff)
Alt text works on Lynx
(turns out it should go on the last <area>, not first)
-rw-r--r--imagemap.py11
-rw-r--r--tests/data/refs/imagemap__--maptype__HTML__alt__svg.out4
2 files changed, 6 insertions, 9 deletions
diff --git a/imagemap.py b/imagemap.py
index a3f6490..9f801b6 100644
--- a/imagemap.py
+++ b/imagemap.py
@@ -141,6 +141,7 @@ class ImageMap(inkex.OutputExtension):
linkindex=int(linkindex[len(CSS_LINK_INDEX)+3:-2])
link=links[linkindex]
href=link['href']
+ if len(shapes[linkindex])==0: alt=link['alt']
path=el.get_path().transform(el.composed_transform()).to_superpath()
bezier.cspsubdiv(path,0.5)
for subpath in path:
@@ -149,19 +150,15 @@ class ImageMap(inkex.OutputExtension):
while i<len(coords):
if coords[i]==coords[(i+1)%len(coords)]: coords.pop(i)
else: i+=1
- if rectifiable(coords): shapes[linkindex].insert(0,{'shape':'rect','coords':rectify(coords),'href':href})
- elif len(coords)>=3: shapes[linkindex].insert(0,{'shape':'poly','coords':coords,'href':href})
+ if rectifiable(coords): shapes[linkindex].insert(0,{'shape':'rect','coords':rectify(coords),'href':href,'alt':alt})
+ elif len(coords)>=3: shapes[linkindex].insert(0,{'shape':'poly','coords':coords,'href':href,'alt':alt})
href=None # because subsequent subpaths must be enclaves
+ alt=None
for i in range(len(shapes)):
- alt=links[i]['alt']
if len(shapes[i])==0: inkex.errormsg(_("The hyperlink \"{}\" could not be added to the output.").format(links[i]['href']))
for j in shapes[i]:
attrs=links[i].copy()
attrs.update(j)
- if attrs['href'] is not None:
- attrs['alt']=alt
- alt=None
- else: attrs['alt']=None
stream.write(bytes(shapemarkup(attrs),'utf-8'))
if __name__ == "__main__":
diff --git a/tests/data/refs/imagemap__--maptype__HTML__alt__svg.out b/tests/data/refs/imagemap__--maptype__HTML__alt__svg.out
index d78824d..8c4e7a1 100644
--- a/tests/data/refs/imagemap__--maptype__HTML__alt__svg.out
+++ b/tests/data/refs/imagemap__--maptype__HTML__alt__svg.out
@@ -1,4 +1,4 @@
<area shape=rect coords=25,20,75,30 href=http://example.com/1 alt=A>
-<area shape=rect coords=25,45,45,55 href=http://example.com/2 alt=B>
-<area shape=rect coords=55,45,75,55 href=http://example.com/2>
+<area shape=rect coords=25,45,45,55 href=http://example.com/2>
+<area shape=rect coords=55,45,75,55 href=http://example.com/2 alt=B>
<area shape=rect coords=25,70,75,80 href=http://example.com/3 alt=C>