-
Notifications
You must be signed in to change notification settings - Fork 83
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
fix!: ensure HTML ID attributes are unique #607
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #607 +/- ##
==========================================
+ Coverage 90.84% 90.85% +0.01%
==========================================
Files 46 46
Lines 5417 5423 +6
==========================================
+ Hits 4921 4927 +6
Misses 496 496 ☔ View full report in Codecov by Sentry. |
This looks great, thanks! However, it looks like the formatting used for the new ID values shouldn't have a space. According to a W3Schools page:
Could you revise to use a hyphen instead? |
6635b4b
to
efac96e
Compare
Just updated it. I also applied the same rule to the column label and updated the test to have a column with a space in the name to demonstrate that. |
@@ -225,7 +236,7 @@ def create_columns_component_h(data: GTData) -> str: | |||
colspan=len(stub_layout), | |||
style=_flatten_styles(styles_stubhead), | |||
scope="colgroup" if len(stub_layout) > 1 else "col", | |||
id=_process_text_id(stub_label), | |||
id=_create_element_id(table_id, stub_label), |
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.
Just noting for the future (nothing needs to be done here) but the stub doesn't really have an ID value (I suppose the column that created the stub labels could be it?) and it often won't have a label unless tab_stubhead()
was called.
The issue with all this is that for the stubhead <th>
element we get id=""
, which is invalid HTML according to https://validator.w3.org/nu/.
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 is so close, but I have a few suggested changes.
@BenGale93 Sorry to reverse course here a bit, but I did notice that if labels are used to compose element IDs, there's a good chance one might get duplicate ID values (since labels can be user-modified but column names are immutable and usually always unique). Could you address these changes? I tried out all of the suggested changes locally and tests pass and the element IDs look reasonable to me. |
@rich-iannone makes total sense. Will work on this in a few hours time. Thanks for the review! |
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.
LGTM!
Summary
Previously, if you had multiple GT HTML tables inside a single document, that had column names in common, you would have repeated HTML ID attributes. This PR makes these ID attributes unique by prepending the table ID, if it exists.
Related GitHub Issues and PRs
Checklist