mdbook-termlink
An mdBook preprocessor that automatically links glossary terms throughout your documentation.
Features
- Automatic Term Linking: Parses glossary terms from Markdown definition lists and links them throughout your book
- Smart Context Detection: Skips code blocks, inline code, existing links, headings, and images
- Tooltip Preview: Displays term definitions on hover via HTML
titleattribute - Configurable Matching: Case-insensitive matching with link-first-only option per page
- Exclude Pages: Skip specific pages from processing using glob patterns
- Term Aliases: Define alternative names that link to the same glossary entry
- Short Form Support: Automatically handles terms like "API (Application Programming Interface)"
Installation
From crates.io
From source
Quick Start
1. Configure your book.toml
[]
= "reference/glossary.md"
2. Create a glossary file
Use Markdown definition lists in your glossary:
API (Application Programming Interface)
: A set of protocols and tools for building software applications.
REST
: Representational State Transfer, an architectural style for distributed systems.
JSON
: JavaScript Object Notation, a lightweight data interchange format.
3. Build your book
Terms in your chapters will automatically link to their glossary definitions with tooltip previews on hover.
Configuration
All configuration options with their defaults:
[]
# Path to the glossary file (relative to src directory)
= "reference/glossary.md"
# Only link the first occurrence of each term per page
= true
# CSS class applied to glossary term links
= "glossary-term"
# Whether term matching should be case-sensitive
= false
# Pages to exclude from term linking (glob patterns)
= ["changelog.md", "appendix/*"]
# Alternative names for terms
[]
= ["apis", "api endpoints"]
= ["RESTful"]
Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
glossary-path |
String | "reference/glossary.md" |
Path to glossary file relative to src/ |
link-first-only |
Boolean | true |
Only link first occurrence per page |
css-class |
String | "glossary-term" |
CSS class for term links |
case-sensitive |
Boolean | false |
Case-sensitive term matching |
exclude-pages |
Array | [] |
Glob patterns for pages to skip |
aliases |
Map | {} |
Alternative names for terms |
Styling
Add custom styles for glossary links in your book.toml:
[]
= ["custom.css"]
Example custom.css:
}
}
How It Works
-
Glossary Parsing: Parses your glossary file for definition lists (term followed by
: definition) -
Term Extraction: Extracts each term with its anchor, short form (if present), and definition
-
Content Processing: Processes each chapter, matching terms using word boundaries while skipping protected contexts
-
Link Generation: Replaces terms with HTML links including tooltip definitions:
API
Requirements
- mdBook 0.5.0 or later
- Rust 1.88.0 or later (for building from source)
Development
# Run all tests (unit, integration, and e2e)
# Run only e2e tests (requires mdBook installed)
# Run clippy
# Check formatting
# Build release
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.