Add glossary hook#270
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a MkDocs hook that derives glossary terms from reference/glossary.md and injects Material-style tooltip markup into rendered paragraph HTML.
Changes:
- Registers the new glossary abbreviations hook in
mkdocs.yml. - Adds
extra.glossary_tooltips.exclude_termsconfiguration. - Implements glossary parsing, term filtering, paragraph scanning, and
<abbr title="...">injection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
mkdocs.yml |
Enables the glossary hook and configures excluded tooltip terms. |
hooks/glossary_abbreviations.py |
Adds glossary extraction and rendered HTML tooltip injection logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
eshaben
left a comment
There was a problem hiding this comment.
Not sure if you already did this, but we should review the docs repo to see anywhere that we are linking directly to the glossary page and remove those links in favor of the tooltips.
For example in the introduction the FRAME link goes to the glossary, so we should remove it: https://docs.polkadot.com/parachains/customize-runtime/#introduction
eshaben
left a comment
There was a problem hiding this comment.
can you pls add docs to the beginning of the hook, like we do with other hooks?
This PR adds a hook that uses reference/glossary.md as the single source of truth for glossary terms. During the MkDocs build, it extracts glossary entries from headings and their definitions, filters out excluded terms from mkdocs.yml, and then adds tooltip HTML only to eligible paragraph text after Markdown has already been rendered to HTML. This avoids tooltips in headings, links, code, bold labels, and navigation cards while still using Material’s tooltip styling.
Hook Flow:
reference/glossary.mdThe hook reads glossary headings and definitions.
The hook builds an in-memory term map.
Example:
{"Runtime": "The runtime represents..."}The hook removes terms configured in
mkdocs.yml.Example:
exclude_terms: ["Polkadot"]MkDocs renders each Markdown page to HTML.
The hook scans the rendered HTML.
The hook only processes normal
<p>paragraph text.The hook skips paragraphs inside
.grid.cards.The hook skips text inside links, code, strong/bold, buttons, etc.
The hook injects
<abbr title="...">Term</abbr>.Material displays the tooltip.
This PR needs to be merged with this one: polkadot-developers/polkadot-docs#1686