deepayan / r-refmans

1 stars 2 forks source link

WCAG 2.2 violations #3

Open eliocamp opened 1 month ago

eliocamp commented 1 month ago

We are compiling a list of WCAG 2.2 violations here (to not overwhelm the repo) : https://docs.google.com/spreadsheets/d/1JNxIHLDHpffxCehWCOvfUiZ-QDP8SpZ_n_WwDdjdZlg/edit?gid=0#gid=0

Feel free to comment on them either here or there. We're checking this with the IBM Equal Accessibility checker extension.

eliocamp commented 1 month ago

One of the violations is that code blocks are "tabbable" but are not interactive. This is because they have tabindex=0 and comes from the code highlighting library prims.js and not from R itself so I don't know how or if to fix it.

eliocamp commented 1 month ago

Here's a possible patch that fixes some of the issues.

This increases the h1 contrast, adds the "presentation" role to tables used for layout in arguments and DESCRIPTION information and adds the "lang" attribute to the HTML file, using the Language of the package, if available.

Let me know what you think.

Index: doc/html/R-nav.css
===================================================================
--- doc/html/R-nav.css  (revision 86890)
+++ doc/html/R-nav.css  (working copy)
@@ -37,7 +37,7 @@

 h1 {
     background: white;
-    color: rgb(55%, 55%, 55%);
+    color: #6E6E6E;
     font-family: monospace;
     font-size: 1.4em; /* x-large; */
     text-align: center;
Index: src/library/tools/R/Rd2HTML.R
===================================================================
--- src/library/tools/R/Rd2HTML.R   (revision 86890)
+++ src/library/tools/R/Rd2HTML.R   (working copy)
@@ -1005,8 +1005,8 @@
                leavePara(FALSE)
                if (!inlist) {
                    switch(blocktag,
-                           "\\value" =  of1('<table>\n'),
-                           "\\arguments" = of1('<table>\n'),
+                           "\\value" =  of1('<table role = "presentation">\n'),
+                           "\\arguments" = of1('<table role = "presentation">\n'),
                            "\\itemize" = of1("<ul>\n"),
                            "\\enumerate" = of1("<ol>\n"),
                            "\\describe" = of1("<dl>\n"))
@@ -1710,9 +1710,9 @@
                  paste0("<a href=\"https://orcid.org/\\1\">",
                         "<img alt=\"ORCID iD\"",
                         if(dynamic)
-                            "src=\"/doc/html/orcid.svg\" "
+                            " src=\"/doc/html/orcid.svg\" "
                         else
-                            "src=\"https://cloud.R-project.org/web/orcid.svg\" ",
+                            " src=\"https://cloud.R-project.org/web/orcid.svg\" ",
                         "style=\"width:16px; height:16px; margin-left:4px; margin-right:4px; vertical-align:middle\"",
                         " /></a>"),
                  desc["Author"])
@@ -1729,7 +1729,7 @@
     ##   AUTHORS COPYRIGHTS
     ## </TODO>

-    c("<table>",
+    c("<table role='presentation'>",
       sprintf("<tr>\n<td>%s:</td>\n<td>%s</td>\n</tr>",
               names(desc), desc),
       "</table>")
Index: src/library/tools/R/pkg2HTML.R
===================================================================
--- src/library/tools/R/pkg2HTML.R  (revision 86890)
+++ src/library/tools/R/pkg2HTML.R  (working copy)
@@ -151,6 +151,9 @@

     ## Now to make a file with header + DESCRIPTION + TOC + content + footer

+    lang <- read.dcf(descfile, fields = "Language")[1, 1]
+    if (is.na(lang)) lang <- "en"
+
     hfcomps <- # should we be able to specify static URLs here?
         HTMLcomponents(title = paste0("Help for package ", pkgname), logo = FALSE,
                        up = NULL, top = NULL,
@@ -159,7 +162,8 @@
                        dynamic = FALSE, prism = prism,
                        doTexMath = TRUE,
                        texmath = if (use_mathjax) "mathjax" else texmath,
-                       MATHJAX_CONFIG_STATIC = mathjax_config)
+                       MATHJAX_CONFIG_STATIC = mathjax_config, 
+                       lang = lang)

     writeHTML <- function(..., sep = "\n", append = TRUE)
         cat(..., file = out, sep = sep, append = append)
Index: src/library/tools/R/toHTML.R
===================================================================
--- src/library/tools/R/toHTML.R    (revision 86890)
+++ src/library/tools/R/toHTML.R    (working copy)
@@ -432,7 +432,8 @@
                            MATHJAX_CONFIG_STATIC = file.path(Rhome, "doc/html/mathjax-config.js"),
                            PRISM_JS_STATIC = c("https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js",
                                                "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-r.min.js"),
-                           PRISM_CSS_STATIC = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css")
+                           PRISM_CSS_STATIC = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css", 
+                           lang = "en")
 {
     header <- character(0)
     footer <- character(0)
@@ -475,7 +476,7 @@
     }

     addh('<!DOCTYPE html>',
-         "<html>",
+         sprintf("<html lang=%s>", lang),
          '<head><title>')

     ## headtitle <- strwrap(.Rd_format_title(.Rd_get_title(Rd)),
llrs commented 1 month ago

I'll create some issues for several big issues from the table above so that it is easier to track them and know how to fix them.