✨ Add sd_custom_roles: config-defined badge roles with baked tooltips#295
Open
chrisjsewell wants to merge 2 commits into
Open
✨ Add sd_custom_roles: config-defined badge roles with baked tooltips#295chrisjsewell wants to merge 2 commits into
chrisjsewell wants to merge 2 commits into
Conversation
Add an ``sd_custom_roles`` config option (parallel to ``sd_custom_directives``) to register badge roles that inherit a built-in badge role (``bdg``, ``bdg-<color>``, ``bdg-*-line``, ``bdg-link-*``, ``bdg-ref-*``) and optionally bake in a default ``tooltip``. This is the recommended way to declare repeated status badges (stable/beta/deprecated) once, instead of retyping the ``; tooltip`` suffix at every use site. - A baked tooltip is only the default: a per-instance ``; tooltip`` suffix overrides it. The shared badge-role constructor gains a ``tooltip`` keyword, used as the fallback when no suffix is present; a tooltip-less custom role is byte-identical to the role it inherits. A baked tooltip also applies to the bare form of link/ref badges (where the suffix grammar refuses to split) and overrides a reference's automatic title. - Config validation: dict-of-dicts, unknown keys rejected, ``inherit`` a string, and the role name must be non-empty and whitespace-free (unicode, case and colons are accepted; docutils looks roles up case-insensitively). - Registration reconciles on every ``config-inited`` against docutils' process-global role registry: our own names are refreshed (picking up tooltip/inherit edits in-process), names dropped from the config are unregistered (no stale leak into a later build or sibling app), and a name clashing with a foreign role - another extension's, or a docutils canonical role such as ``code``/``math``/``strong`` - is skipped with a warning. - The field is fully TOML-representable and picked up by the config table. - Docs frame the ``; tooltip`` suffix as the one-off escape hatch, with custom roles as the primary pattern (rst + myst examples, cross-linked with the custom directives docs, and a note recommending a ``bdg-`` name prefix).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #295 +/- ##
==========================================
+ Coverage 92.63% 92.64% +0.01%
==========================================
Files 13 13
Lines 1371 1428 +57
==========================================
+ Hits 1270 1323 +53
- Misses 101 105 +4
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
sd_custom_roles— the role counterpart tosd_custom_directives(#194), and the follow-up to the badge tooltips of #286. Repeated status badges get defined once inconf.py, fully TOML-representable:Then
:bdg-stable:`v1.2`everywhere — no retyped; tooltipsuffixes. The docs present this as the primary pattern for repeated semantics, with the per-instance suffix as the one-off escape hatch (which still overrides a baked tooltip; precedence documented and tested).Behaviour
bdg,bdg-<color>, line/link/ref variants; extension point for icon/button roles noted in-code). A baked tooltip also applies to bare-form link/ref badges — where the suffix grammar deliberately refuses to split — and overrides a ref's automatic title.inheritwarns and skips, unparseable role names rejected.code,mathorstrongis warn+skipped instead of silently hijacking core rendering; and registrations are reconciled every build with ownership markers, so under in-process rebuilds (sphinx-autobuild) tooltip edits take effect, removed roles stop resolving, and nothing leaks between apps — matchingsd_custom_directivesbehaviour. Both locked by regression tests (including a three-apps-in-one-process test that bypasses the fixture cleanup which had masked the leak).main(the shared-constructor refactor is behaviour-preserving — review diffed an exhaustive page of every family).Verification
SdConfigfield requires); docs-nWwith live examples rendering in the docs' own conf.py