Skip to content

Unused links in HTML output of code chunks #1030

Description

@mine-cetinkaya-rundel

This issue came up in the review of the accessible cheatsheets, see mine-cetinkaya-rundel/html-cheatsheets#4 for the original issue.


Suppose you have the following code chunk in a Quarto document with format: html.

library(tidyverse)
mtcars %>%
  filter(mpg > 30) %>%
  ggplot(aes(x = mpg, y = disp)) +
  geom_point()

The resulting HTML is as follows (with indentation added by me to make it a bit easier to read)

<div class="sourceCode cell-code" id="cb5">
   <pre class="sourceCode r code-with-copy">
      <code class="sourceCode r">
         <span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>mtcars <span class="sc">%&gt;%</span></span>
         <span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(mpg <span class="sc">&gt;</span> <span class="dv">30</span>) <span class="sc">%&gt;%</span></span>
         <span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> mpg, <span class="at">y =</span> disp)) <span class="sc">+</span></span>
         <span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_point</span>()</span>. 
      </code>
      <button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button>
   </pre>
</div>

Note that each line of code has an href. They're area-hidden, which is good, but the question is are they needed? Based on the original issue linked above:

  • If the answer is "yes, they are needed", then "provide text within the links that describe the functionality and/or target of that link."
  • If the answer is "no, they are not needed", then "remove the empty link".

cc @batpigandme

Activity

  1. jjallaire commented on May 31, 2022

    @jjallaire
    Collaborator

    That HTML is generated by Pandoc (I believe that it is there for line numbers but I'm not 100% sure). We might want to file this issue with Pandoc so they can handle/exclude/annotate as appropriate for all consumers of Pandoc HTML output not just Quarto.

  2. cderv commented on Jun 1, 2022

    @cderv
    Member

    Yes they are used by Pandoc for line numbering. See result of where the <a> are filled

    ---
    title: "Test"
    format: html
    ---
    
    ```{.r .numberLines}
    library(tidyverse)
    mtcars %>%
      filter(mpg > 30) %>%
      ggplot(aes(x = mpg, y = disp)) +
      geom_point()
    ```

    The aria-hidden have been added following a report by @jooyoungseo in jgm/pandoc#6352 as they were not even there before.

    If there is more to add, I think that would be in Pandoc (even in https://github.com/jgm/skylighting)

    Note also that if code-link: true is used with a knitr code chunk, the spans won't be here because downlit does not handle yet the line numbering. This is on the TODO and I'll remember to add the missing part if we can't reuse Pandoc numbering.

  3. jooyoungseo commented on Jun 2, 2022

    @jooyoungseo
    Collaborator

    @mine-cetinkaya-rundel

    • If the answer is "yes, they are needed", then "provide text within the links that describe the functionality and/or target of that link."

    For numberLine = FALSE, keeping the empty anchor with aria-hidden would suffice. If you provide any text for this empty anchor, that content text will be announced before every single code line, which would be very annoying for screen reader users. Note that the code block anchor is not really meaningful until the users want to reference to any specific code line URL. Screen reader users can obtain a code line anchor URL/ID by clicking the current code line via spacebar. When numberLines = TRUE, the visible line numbering is announced to screen readers because each anchor would get a line number as text content. This is an understandable annoyance.

  4. added this to the Future milestone on Jun 7, 2022
  5. cwickham commented on Jul 7, 2026

    @cwickham
    Member

    Closing. Based on comments above, the code-line-numbers "off" case is currently handled appropriately.

    The above discussion suggests the code-line-numbers "on" case is OK (at least, an "understandable annoyance") but it does currently give an axe-core violation. See #14655 for discussion.

  6. modified the milestones: Future, v1.10 on Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions