-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
docs: fix heading level a11y issue #5679
Conversation
Looks like there were some (unrelated) test timeouts -- any way to re-run those? |
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.
Actually, the heading levels was intentional see: #2390.
10c7cdd
to
8e3b6e4
Compare
I've removed the scrollable region a11y issue from this PR because this change is becoming more complex. I'll submit a fix for that in a separate PR. |
I managed to get the offending headings removed from the TOC, but I had to add some custom markdown parsing logic to do it. Since there was no existing way to distinguish between level-4 headings we wanted to show up in the TOC and ones that we didn't, I added custom attribute parsing similar to Pandoc. Given this line of markdown: #### This is a heading { .red #important data-something=true } The markdown renderer converts it to the following HTML. <h4 class="red" id="important" data-something="true">This is a heading</h4> During markdown processing, we are then able to determine whether or not to add a subsection based on the presence of the new I only attempt attribute extraction on headings for now, but it could be theoretically applied to other elements if desired. One caveat is that the Svelte block syntax (e.g. I'm willing to write tests for the new attribute extraction function if desired, but it doesn't seem like the site has very many tests at the moment. I was unable to run the site-specific tests and it doesn't look like they're being automatically run in a pipeline anywhere. |
This change to the markdown parsing won't be compatible when we we migrate to kit and the new docs handling, we could add this Could we not just make those first set of links with heading level 4 a special case and not render them? I don't think we need this complexity in the parser for what is a very niche issue that occurs exactly once (and that should be solved by having better headings imo). Our custom markdown syntax is challenging enough to figure out for contributors as it is, I'm opposed to making it even worse. |
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.
marking this as changes requested instead of approved
@pngwn that makes sense, thanks for the review. I agree that the new Instead of looking for |
This is a bit awkward which isn't completely unexpected. I think I imagined this would go in the actual component It wouldn't actually break them now because the Modifying the parser as you suggested is one solution, but that will have the same problem when we migrate, because the new parser is shared by all documentation sites. There are two options: either we add some custom logic for the svelte docs specifically (either in the parser to avoid generating subsections or in the component to prevent rendering for that section) or we figure out a way to add these subsections in the side navigation without breaking the layout (making the nav structure consistent for all sections). |
Rather than hide the headings, it might be nice to show a short version of them in side sidebar (like in #6480) |
If we want to show a short version in the sidebar, we could add logic inside the /docs route on svelte.dev to change the title of those sections before rendering: svelte/site/src/routes/docs/index.svelte Lines 2 to 5 in a6fbf7f
Since slugs will be changing eventually, we could map original section titles to a short version, e.g. Not having to hide anything from the table of contents means we shouldn't have to do any additional markdown processing. |
@@ -1,6 +1,23 @@ | |||
<script context="module"> | |||
const title_replacements = { | |||
'1_export_creates_a_component_prop': 'props', |
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.
this seems a bit hard to discover to me compared to if it were in the markdown. though I suppose I'm slightly less worried about that because you could see something happening in the sidebar. but it might be tough to trace it back to this
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.
Yeah, it's not the most obvious place. However, I don't think there's a way to have it in the markdown without implementing custom parsing logic.
At least the effect of this breaking is small -- the sidebar titles would use the section titles instead of the abbreviated version.
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 think this is a pretty reasonable place to have it: it is specific to this view rather than an important part of the docs.
The only other place it could go (without implementing custom parsing logic) is in the Docs
component in site-kit, which would be very difficult to discover. One alternative could be add it to the YAML frontmatter as a map of full -> short heading titles, would require a little work but doable.
I think this is good for now.
I've removed the special markdown parsing logic per the feedback above. Instead, the One downside with this is that the title will not be replaced if the slug changes. If that happens unexpectedly, the longer titles will start appearing in the TOC again. I couldn't think of a better key to match on, but let me know if you have any alternatives. |
This resolves one of the Axe Accessibility violations listed in #5678
h3
to anh5
. I changed theh5
s to anh4
.Ensure that scrollable region has keyboard access (113 instances). The code blocks were scrollable but were not keyboard-focusable. This meant that a user unable to use a mouse would be unable to scroll the code blocks and content could be obscured.Since this PR is becoming more complex, I'll be submitting these changes in a separate PR.A side effect of fixing the heading levels is that additional items appear in the Table of Contents, presumably since
h4
s are shown in the TOC by default buth5
s are not.Before:
After:
Also,
export
and$
are no longer highlighted in the affected headings due to differences in h4/h5 styling.Before:
After:
Please let me know if either of these prevent merging this PR.