-
Notifications
You must be signed in to change notification settings - Fork 38
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
Implement row level table headings to allow accessible tables with row headings #214
Conversation
9b6ecfe
to
f48534c
Compare
211607d
to
7af1819
Compare
Looking at vmg/redcarpet@27dfb2a, I'm not sure it actually helps with table row headers – I think it just makes it possible to know whether a given cell is a column header within the context of the |
Yeah, the problem is if I implement a custom So I could use it to implement row headers, but we'd lose column headers (which work at the moment). |
Ah! I totally mis-interpreted your comment. I was interpreting it as though that commit would bring native row headers to redcarpet, meaning we don't have to do anything at all – rather than that it would allow us to instead use the Makes sense now 👍🏻 |
Yep, sorry - I should clarify the comment :) |
7af1819
to
813a596
Compare
Updated to clarify the comment, and to use |
f2a6e60
to
23ae02e
Compare
This requires alphagov/tech-docs-gem#214 to be released first - the current version of the tech docs template doesn't support row headers in markdown tables. Alternatively we could document that you need to use HTML tables to set row level headings.
Sometimes, tables have row-level headings as well as column level headings. To be accessible, these need to be marked up as `<th>` tags. Otherwise users of screen readers and other assistive technology may not be able to work out that they're table headings rather than ordinary table cells.
23ae02e
to
3de782e
Compare
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.
Makes sense to me. I have got 1 query about the space after the #
being required.
I'm also aware it's been a long time since I've written any Ruby, so it might be worth getting a second review from someone who writes Ruby regularly.
# Despite the hackiness, this substitution should work for all cases | ||
# where the table cell just includes simple text (with no other markup). | ||
|
||
body_with_row_headers = body.gsub(/<td># ([^<]*)<\/td>/, "<th scope=\"row\">\\1</th>") |
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.
Am I right in thinking the space between the #
and the text is required for this pattern to match?
From testing, it looks like redcarpet will happily make something a heading without the space (e.g. #Hello world
becomes an H1), so I'm wondering if it's worth being consistent on that here.
(Conversely, CommonMark requires the space, but does acknowledge that many implementations don't)
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, this pattern requires it. I wasn't sure whether it was needed in the spec or not.
🤔 🤔 Not sure whether to keep the space or not...
@@ -0,0 +1,35 @@ | |||
RSpec.describe GovukTechDocs::TechDocsHTMLRenderer do | |||
describe "#render a table" do | |||
it "renders tables with row headings" do |
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.
Nice test 💯
This allows us to handle the more complex case where table headings contain other markup (e.g. the heading might have an `<em>` tag, as per the test). It feels less hacky than using a regex, but it's quite a bit more code so I'm not 100% sure whether it's an improvement.
c7965e7
to
c061010
Compare
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 like the use of Nokogiri here. ⭐
It's verbose, true, but it's nice and readable. It's clear what you're doing at each step.
As suggested in our Slack conversation, I'd like to see the test split but that's not a blocker 😉
I see you split the test while I was still writing my comment 😄 Nice |
Sometimes, tables have row-level headings as well as column level headings.
To be accessible, these need to be marked up as
<th>
tags. Otherwise users of screen readers and other assistive technology may not be able to work out that they're table headings rather than ordinary table cells.