✨ Add tooltip suffix syntax to badge roles#286
Open
chrisjsewell wants to merge 1 commit into
Open
Conversation
Badge roles now accept a trailing `; tooltip` suffix, rendered as a native HTML `title` attribute (closes #81). The suffix is split on the last unescaped `;` (a literal `;` is written `\;`), mirroring the icon roles' string grammar via the new `split_tooltip` helper. Since `;` is a legal character in URLs and reference targets, the `bdg-link-*`/`bdg-ref-*` families only accept the suffix after a complete explicit `title <target>` form (the `;` must follow the closing `>`); a bare target is never split, so existing targets containing `;` render byte-identically to before. The `\;` escape is resolved uniformly for both parsers (docutils NUL-encodes escapes, MyST forwards backslashes verbatim). - plain badges use a new `sd_badge` node (a `nodes.inline` whose HTML visitor emits `title` when set, with explicit passthrough visitors for latex/text/man/texinfo); output without a tooltip is byte-identical to before (only the doctree node name changes, hence the badge-basic fixture regeneration) - `bdg-link-*` set `reftitle` on the reference (native `title`) - `bdg-ref-*` carry the tooltip across cross-reference resolution using the #281 marker-class + document-stash pattern (an arbitrary attribute does not survive resolution), applied as `reftitle` by a post-transform that runs after the resolver; no marker/attribute leaks into output Also removes a stale `TODO escape HTML` on the button `:tooltip:` option (the HTML writer already escapes attribute values) and the dead commented-out `reftitle` code in the link badge role.
965d639 to
2d25d06
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #286 +/- ##
==========================================
+ Coverage 90.72% 91.85% +1.13%
==========================================
Files 13 13
Lines 1207 1301 +94
==========================================
+ Hits 1095 1195 +100
+ Misses 112 106 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds native
title-attribute tooltips to all badge role families via a trailing; tooltipsuffix — a small, parser-portable string grammar in the spirit of the icon roles'name;height;classes.Design
bdg*: split on the last unescaped;(\;escapes a literal semicolon — now working in MyST too, where backslashes previously passed through literally). A trailing bare;is kept in the label (documented).bdg-link*/bdg-ref*: semicolons are legal in URLs and ref targets, so tooltips on these families require the explicittext <target>form — the split only fires after the closing>, and a;inside<...>or in a bare target is never a separator. Verified byte-identical to main for every semicolon-in-target shape (.../a;b,?x=1;y=2,<my;label>), in both rst and MyST.sd_badgeinline node (byte-identical<span>when no tooltip — proven by full-page diffs); link badges usereftitlenatively;bdg-reftooltips survive cross-reference resolution via a marker-class stash/graft pair (same proven mechanism as 🐛 Fix button-ref target whitespace and nested content #281's button transforms, fully disjoint from them — coexistence tested in one document). Tooltip text is HTML-escaped by the writer (tested with quotes/</&).:tooltip:escaping is now test-locked and its stale TODO removed.titletooltips aren't keyboard/touch accessible — essential information belongs in visible text.Verification
;) — the redesign above is the fix, and the re-review independently confirmed every corruption case now renders byte-identical to main in both parsers, plus ten fresh regex edge cases (multiple<...>groups,>inside tooltips, escaped\>targets, title-less forms) with the invariant: branch output = main's parse of the prefix + tooltip, never a novel corruption.tests/test_badge_tooltips.py(29 cases) includes regression tests for every corruption shape found in review.Closes #81