-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccessibility.lua
More file actions
50 lines (46 loc) · 1.33 KB
/
Copy pathaccessibility.lua
File metadata and controls
50 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- Pandoc Lua filter for injecting accessibility metadata
-- Usage: pandoc input.md --lua-filter=accessibility.lua -o output.html
function Image(img)
local longdesc = img.attributes["longdesc"]
if longdesc then
img.attributes["aria-description"] = longdesc
if img.caption and #img.caption > 0 then
img.attributes["title"] = pandoc.utils.stringify(img.caption)
end
img.attributes["accessibility-description"] = longdesc
end
if not img.attr.attributes["alt"] then
if img.caption and #img.caption > 0 then
img.attr.attributes["alt"] = pandoc.utils.stringify(img.caption)
else
img.attr.attributes["alt"] = ""
end
end
return img
end
function Link(link)
if link.title then
link.attributes["aria-label"] = link.title
end
return link
end
function Div(div)
local classes = div.attributes["class"] or ""
if classes:find("image%-description") then
div.attributes["aria-hidden"] = "true"
div.attributes["role"] = "note"
end
if classes:find("ocr%-text") then
div.attributes["aria-hidden"] = "true"
div.attributes["role"] = "note"
end
if classes:find("ui%-controls") then
div.attributes["aria-hidden"] = "true"
div.attributes["role"] = "note"
end
return div
end
function Header(header)
header.attributes["aria-level"] = tostring(header.level)
return header
end