Adding in alt text checker#261
Conversation
Signed-off-by: matthewberobinson <matthewberobinson@yahoo.com>
Signed-off-by: matthewberobinson <matthewberobinson@yahoo.com>
Signed-off-by: matthewberobinson <matthewberobinson@yahoo.com>
| data.frame(character = rep("c",length(close_rd_bracket_open_cly_loc)), | ||
| position = close_rd_bracket_open_cly_loc)) | ||
|
|
||
| alt_text_loc <- gregexpr("alt-text",line)[[1]] |
There was a problem hiding this comment.
I would update to,
alt_text_loc <- gregexpr("alt-text|fig-alt",line)[[1]]
to allow alternative ways of writing alt text as seen in ./RAP/rap-case-studies.qmd
There was a problem hiding this comment.
That's a really good catch thank you
Ethan-Roy-2025
left a comment
There was a problem hiding this comment.
The check looks good and functions as I would expect it to when run locally. check_project_for_alt_text() is an impressive function !!
I have left a specific change to line 50 of alt_text_checker.R, as it seems some images with alt text are failing, because they use "fig-alt" instead of "alt-text" (please see images on the ./RAP/rap-case-studies.qmd page). This allows gregexpr() to accept both.
More generally, I think the alt_text_checker.R script would benefit from some commenting to explain what each function is doing. I found it took me a while to fully get to grips with it, so some comments explaining what is going on may make it easier for new people to pick this up in the future.
I also think that there should be some control on the warnings generated by the check_project_for_alt_text() function. When run locally it generates 50 or more warnings. As you can only view the first 50 warnings with warning(), it may be best to handle the many (I assume expected) warnings to prevent them masking another warning that may need attention. These seem to come from 2 places,
- The
check_all_have_alt_text()function throws a lot of longer object length is not a multiple of shorter object length warnings, as the checks forboolean_2shortens the vector each time which means that it repeats FASLE at the end of the vector to match the original vector size. I think this is intended, as it does behave as expected for some fringe test cases (e.g. two images with alt text in one line, an image with alt text before or after some text with unrelated brackets, jumbled up order of the expected brackets). I did have a play around with finding an alternate way of pattern matching the vector that does not shorten the vector each time, but was not successful, I wonder if it would benefit from adding thesuppressWarnings()function to this function. - The
readLines()function throws incomplete final line found on ... warnings. This is because some.qmdfiles have no clear end of line marker. There appears to be an optional argument to suppress this inreadLines(file_name, warn = FALSE)
Also in thinking how this will be applied to the Analyst's Guide, I assume this check will highlight which images colleagues will need to add alt text to. To support this process I think it would be useful to add guidance on adding alt text to the README.md or CONTRIBUTING.md. I think this would help those who will need to add alt text while also (hopefully) encouraging colleagues to add alt text as they add a new image.
Overview of changes
This is a quick PR uploading code to check whether the markdown uses alt-text, it spits out a list of files and line numbers where alt-text is missing.
There is also a yaml script to run this, with a manual trigger, we can alter the trigger as needed.
It doesn't take long to run.
Why are these changes being made?
Just to provide us of better coverage in terms of accessibility.
Detailed description of changes
Two scripts added, an R script to run through all the quarto files, find locations where there is something of the form
{z} but within z there isn't anything beginning alt-text (note as it stands this means you can put in an empty alt-text = "" and it will pass, which isn't great, but I expect that if you've bothered to write it out then you'll have added in alt text, copy and pasting also would include previous alt-text where testing for duplicates isn't sensible in case there is reason to duplicate.
Issue ticket number/s and link
Checklist before requesting a review