-
Notifications
You must be signed in to change notification settings - Fork 24
add skill to find and improve alt text for pkgdown documentation #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9730e26
add skill to find and improve alt text for pkgdown documentation
EmilHvitfeldt 0f46f08
fix link on readme
EmilHvitfeldt deebfc2
convert alt-text to use progressive disclosure
EmilHvitfeldt 83abc38
add stub skill for quarto-alt-text
EmilHvitfeldt 8b794b6
Merge branch 'main' into pkgdown-alt-text
EmilHvitfeldt 4a4ebf7
delete old quarto-alt-text
EmilHvitfeldt 0095c05
clean up alt-text readms
EmilHvitfeldt 91848c3
Merge remote-tracking branch 'origin/pkgdown-alt-text' into pkgdown-a…
EmilHvitfeldt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| # Alt Text in pkgdown Sites | ||
|
|
||
| This reference covers how to find images and add alt text across a pkgdown site. | ||
|
|
||
| ## Where images appear | ||
|
|
||
| | Location | Image type | Can have alt text? | | ||
| |----------|------------|-------------------| | ||
| | `vignettes/*.Rmd` or `vignettes/*.qmd` | code-generated plots | Yes — `fig.alt` chunk option | | ||
| | `vignettes/*.Rmd` | static images via `knitr::include_graphics()` | Yes — `fig.alt` chunk option | | ||
| | `README.Rmd` / `README.md` | code-generated plots | Yes — `fig.alt` chunk option | | ||
| | `README.Rmd` / `README.md` | markdown images `` | Yes — fill in the bracket | | ||
| | `README.Rmd` / `README.md` | HTML `<img src=...>` tags | Yes — add `alt="..."` attribute | | ||
| | `R/*.R` `@examples` | code-generated plots | **No — pkgdown limitation** | | ||
|
|
||
| There is currently no way to add alt text to plots generated in `@examples` blocks. | ||
| Focus effort on vignettes and README. | ||
|
|
||
| ## Step 1 — Find missing alt text | ||
|
|
||
| ### Find chunks missing fig.alt in vignettes | ||
|
|
||
| ```bash | ||
| # Find chunks that already have fig.alt (to see what's covered) | ||
| grep -rn "fig\.alt\|fig-alt" vignettes/ | ||
|
|
||
| # Find all plot-producing chunks — each one needs a fig.alt | ||
| grep -rn "ggplot\|geom_\|autoplot\|include_graphics" vignettes/ | ||
| ``` | ||
|
|
||
| Compare the two lists to identify chunks with plots but no `fig.alt`. | ||
|
|
||
| ### Find static images missing alt text | ||
|
|
||
| ```bash | ||
| # Markdown images with empty alt:  | ||
| grep -rn "!\[\](" vignettes/ README.md README.Rmd | ||
|
|
||
| # All markdown images — review each for descriptive alt text | ||
| grep -rn "!\[" vignettes/ README.md README.Rmd | ||
|
|
||
| # HTML <img> tags — check each for a non-empty alt attribute | ||
| grep -rn "<img" vignettes/ README.md README.Rmd | ||
| ``` | ||
|
|
||
| Package logos are commonly written as HTML `<img>` tags at the top of | ||
| `README.Rmd`. Check that the `alt` attribute is present and descriptive: | ||
|
|
||
| ```html | ||
| <!-- Missing alt --> | ||
| <img src='man/figures/logo.png' align="right" height="139" /> | ||
|
|
||
| <!-- Fixed --> | ||
| <img src='man/figures/logo.png' align="right" height="139" | ||
| alt="Package hex logo: a blue hexagon with the package name." /> | ||
| ``` | ||
|
|
||
| ## Step 2 — Audit quality of existing alt text | ||
|
|
||
| When alt text already exists, leave it alone unless it has a concrete problem. | ||
| Only rewrite alt text that fails one of these checks: | ||
|
|
||
| **Relative references** — alt text must be self-contained. Fix phrases like: | ||
| - "A plot identical to the one above…" → describe the plot fully | ||
| - "The same data as shown above…" → name the data explicitly | ||
|
|
||
| **Missing key information** — fix if alt text omits chart type, axis labels, or | ||
| the key pattern. | ||
|
|
||
| **Grammar and spelling errors** — alt text is read aloud by screen readers. | ||
|
|
||
| ## Step 3 — Add fig.alt to Rmd chunks | ||
|
|
||
| The `fig.alt` chunk option works for both code-generated plots and static | ||
| images loaded with `knitr::include_graphics()`. | ||
|
|
||
| ### Hashpipe syntax (preferred) | ||
|
|
||
| ```r | ||
| #| fig.alt: > | ||
| #| Scatter chart of bill length vs. bill depth for 344 penguins | ||
| #| across three species. Gentoo penguins form a distinct cluster | ||
| #| at higher bill depth. Adelie and Chinstrap overlap but separate | ||
| #| along the bill length axis, with Chinstrap skewing higher. | ||
| plot_code_here() | ||
| ``` | ||
|
|
||
| ### Knitr chunk option syntax | ||
|
|
||
| ````markdown | ||
| ```{r penguin-scatter, fig.alt="Scatter chart of bill length vs. bill depth..."} | ||
| plot_code_here() | ||
| ``` | ||
| ```` | ||
|
|
||
| ### Multiple plots in one chunk | ||
|
|
||
| When a chunk produces multiple plots, `fig.alt` accepts a vector — one string | ||
| per plot, in order: | ||
|
|
||
| ```r | ||
| #| fig.alt: | ||
| #| - "Histogram of bill length. Right-skewed distribution with a peak at 45–50mm." | ||
| #| - "Histogram of bill depth. Bimodal distribution with peaks at 15mm and 18mm." | ||
| ``` | ||
|
|
||
| ## Step 4 — Add alt text to static markdown images | ||
|
|
||
| For `` images, fill in the bracket: | ||
|
|
||
| ```markdown | ||
| <!-- Before --> | ||
|  | ||
|
|
||
| <!-- After --> | ||
|  | ||
| ``` | ||
|
|
||
| For purely decorative images, leave the bracket empty intentionally and add a | ||
| comment: | ||
|
|
||
| ```markdown | ||
| <!-- Decorative banner, intentionally no alt text --> | ||
|  | ||
| ``` | ||
|
|
||
| ## Step 5 — Verify | ||
|
|
||
| Because pkgdown does not warn about missing alt text in vignettes, verify by | ||
| re-running the same grep from Step 1 and confirming every plot-producing chunk | ||
| now has a `fig.alt`: | ||
|
|
||
| ```bash | ||
| # Should list every chunk with a plot | ||
| grep -rn "ggplot\|geom_\|autoplot\|include_graphics" vignettes/ | ||
|
|
||
| # Should now match the same chunks | ||
| grep -rn "fig\.alt\|fig-alt" vignettes/ | ||
| ``` | ||
|
|
||
| For the home page, `build_site()` will warn if any README images are still | ||
| missing alt text. | ||
|
|
||
| ## Quarto vignettes (`.qmd`) | ||
|
|
||
| For vignettes using Quarto format, use `fig-alt` (hyphen) instead of `fig.alt` (dot): | ||
|
|
||
| ```r | ||
| #| fig-alt: > | ||
| #| Scatter chart of bill length vs. bill depth for 344 penguins | ||
| #| across three species. | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to have a similar skill for Shiny apps, too. If you wanted to add that, I'd be grateful. Or I'd be happy to just open an issue and come back to it when I have a minute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough about shiny to write a good skill for that :)