Skip to content

Commit 5f7712e

Browse files
panglesdjonludlam
authored andcommitted
Media: add alt text to aria-label for audio and video
As per the recommended solution of: https://www.w3.org/WAI/PF/HTML/wiki/Media_Alt_Technologies
1 parent d523eca commit 5f7712e

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/html/generator.ml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ let rec block ~config ~resolve (l : Block.t) : flow Html.elt list =
214214
let a = Some (class_ (extra_class @ t.attr)) in
215215
[ mk ?a content ]
216216
in
217-
let mk_media_block media_block target content =
217+
let mk_media_block media_block target alt =
218218
let block =
219219
match target with
220-
| Target.External url -> media_block url
220+
| Target.External url -> media_block url alt
221221
| Internal (Resolved uri) ->
222222
let url = Link.href ~config ~resolve uri in
223-
media_block url
223+
media_block url alt
224224
| Internal Unresolved ->
225-
let content = [ Html.txt content ] in
225+
let content = [ Html.txt alt ] in
226226
let a = Html.a_class [ "xref-unresolved" ] :: [] in
227227
[ Html.span ~a content ]
228228
in
@@ -258,14 +258,26 @@ let rec block ~config ~resolve (l : Block.t) : flow Html.elt list =
258258
let extra_class = [ "language-" ^ lang_tag ] in
259259
mk_block ~extra_class Html.pre (source (inline ~config ~resolve) c)
260260
| Math s -> mk_block Html.div [ block_math s ]
261-
| Audio (target, content) ->
262-
let audio src = [ Html.audio ~src ~a:[ Html.a_controls () ] [] ] in
263-
mk_media_block audio target content
264-
| Video (target, content) ->
265-
let video src = [ Html.video ~src ~a:[ Html.a_controls () ] [] ] in
266-
mk_media_block video target content
261+
| Audio (target, alt) ->
262+
let audio src alt =
263+
[
264+
Html.audio ~src
265+
~a:[ Html.a_controls (); Html.a_aria "label" [ alt ] ]
266+
[];
267+
]
268+
in
269+
mk_media_block audio target alt
270+
| Video (target, alt) ->
271+
let video src alt =
272+
[
273+
Html.video ~src
274+
~a:[ Html.a_controls (); Html.a_aria "label" [ alt ] ]
275+
[];
276+
]
277+
in
278+
mk_media_block video target alt
267279
| Image (target, alt) ->
268-
let image src =
280+
let image src alt =
269281
let img =
270282
Html.a
271283
~a:[ Html.a_href src; Html.a_class [ "img-link" ] ]

test/pages/medias.t/index.mld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ Some image:
2525
{2 Links}
2626

2727
{audio:https://upload.wikimedia.org/wikipedia/commons/f/f1/Cri_du_chameau.ogg}
28+
{{audio:https://upload.wikimedia.org/wikipedia/commons/f/f1/Cri_du_chameau.ogg}The sound of a caml}
2829

2930
{1 Video}
3031

3132
{2 References}
3233

3334
{video:flower.webm}
35+
{{video:flower.webm}A video of a blossoming flower}
3436

3537
{2 Links}
3638

test/pages/medias.t/run.t

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This will have produced a file called 'page-index.odoc'.
1010

1111
Link (and generate the HTML):
1212
$ odoc link -P pkg1:_odoc/pkg1/doc _odoc/pkg1/doc/page-index.odoc
13-
File "index.mld", line 41, characters 48-64:
13+
File "index.mld", line 43, characters 48-64:
1414
Warning: Failed to resolve reference ./module-x Path 'module-x' not found
1515
File "index.mld", line 12, characters 28-83:
1616
Warning: Failed to resolve reference ./camezfzeffl.gif Path 'camezfzeffl.gif' not found
@@ -38,15 +38,23 @@ Testing the working references:
3838
$ cat html/pkg1/doc/index.html | grep video
3939
<li><a href="#video">Video</a>
4040
</div><h2 id="video"><a href="#video" class="anchor"></a>Video</h2>
41-
</h3><div><video src="flower.webm" controls="controls"></video></div>
41+
<video src="flower.webm" controls="controls" aria-label="flower.webm">
42+
</video>
43+
<video src="flower.webm" controls="controls"
44+
aria-label="A video of a blossoming flower">
45+
</video>
4246
<video
4347
src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm"
48+
aria-label="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm"
4449
</video>
4550

4651
$ cat html/pkg1/doc/index.html | grep audio
4752
<li><a href="#audio">Audio</a>
4853
</ul><h2 id="audio"><a href="#audio" class="anchor"></a>Audio</h2>
49-
<div><audio src="Cri_du_chameau.ogg" controls="controls"></audio></div>
54+
<audio src="Cri_du_chameau.ogg" controls="controls"
55+
</audio>
56+
<audio
57+
</audio>
5058
<audio
5159
</audio>
5260

0 commit comments

Comments
 (0)