From 48d5c91d16f96ea522cfa04ed0e4bf91f8aad5f2 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 25 Jun 2022 12:44:25 +0000 Subject: If an .Xr macro contains a section argument, write an aria-label attribute such that users of screen readers aren't forced to listen to lengthy and distracting readings like "mdoc, left parenthesis, 7, right parenthesis". Based on a patch from Anna Vyalkova , significantly tweaked by me. --- LICENSE | 5 +++-- mdoc_html.c | 31 ++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/LICENSE b/LICENSE index 0a0fc1ac..8b464f4e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,11 +1,11 @@ -$Id: LICENSE,v 1.22 2021/09/19 11:02:09 schwarze Exp $ +$Id: LICENSE,v 1.23 2022/06/25 12:44:25 schwarze Exp $ With the exceptions noted below, all non-trivial files contained in the mandoc toolkit are protected by the Copyright of the following developers: +Copyright (c) 2010-2022 Ingo Schwarze Copyright (c) 2008-2012, 2014 Kristaps Dzonsons -Copyright (c) 2010-2021 Ingo Schwarze Copyright (c) 1999, 2004, 2017 Marc Espie Copyright (c) 2009, 2010, 2011, 2012 Joerg Sonnenberger Copyright (c) 2013 Franco Fichtner @@ -13,6 +13,7 @@ Copyright (c) 2014 Baptiste Daroussin Copyright (c) 2016 Ed Maste Copyright (c) 2017 Michael Stapelberg Copyright (c) 2017 Anthony Bentley +Copyright (c) 2022 Anna Vyalkova Copyright (c) 1998, 2004, 2010, 2015 Todd C. Miller Copyright (c) 2008, 2017 Otto Moerbeek Copyright (c) 2004 Ted Unangst diff --git a/mdoc_html.c b/mdoc_html.c index 85969a19..63c98aab 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1,7 +1,8 @@ -/* $Id: mdoc_html.c,v 1.343 2022/06/24 11:15:53 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.344 2022/06/25 12:44:25 schwarze Exp $ */ /* - * Copyright (c) 2014-2021 Ingo Schwarze + * Copyright (c) 2014-2022 Ingo Schwarze * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons + * Copyright (c) 2022 Anna Vyalkova * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -665,26 +666,34 @@ mdoc_nm_pre(MDOC_ARGS) static int mdoc_xr_pre(MDOC_ARGS) { - if (NULL == n->child) + char *name, *section, *label; + + if (n->child == NULL) return 0; + name = n->child->string; + if (n->child->next != NULL) { + section = n->child->next->string; + mandoc_asprintf(&label, "%s, section %s", name, section); + } else + section = label = NULL; + if (h->base_man1) - print_otag(h, TAG_A, "chM", "Xr", - n->child->string, n->child->next == NULL ? - NULL : n->child->next->string); + print_otag(h, TAG_A, "chM?", "Xr", + name, section, "aria-label", label); else - print_otag(h, TAG_A, "c", "Xr"); + print_otag(h, TAG_A, "c?", "Xr", "aria-label", label); - n = n->child; - print_text(h, n->string); + free(label); + print_text(h, name); - if (NULL == (n = n->next)) + if (section == NULL) return 0; h->flags |= HTML_NOSPACE; print_text(h, "("); h->flags |= HTML_NOSPACE; - print_text(h, n->string); + print_text(h, section); h->flags |= HTML_NOSPACE; print_text(h, ")"); return 0; -- cgit v1.2.3-56-ge451