Classes
GlossaryDirective
Glossary directive using Mistune's fenced syntax.
Syntax:
:::{glossary}
:tags: tag1, tag2
…
GlossaryDirective
Glossary directive using Mistune's fenced syntax.
Syntax:
:::{glossary}
:tags: tag1, tag2
:sorted: true
:show-tags: true
:collapsed: true
:limit: 3
:::
Options:
- tags: Comma-separated list of tags to filter terms (required)
- sorted: Sort terms alphabetically (default: false, preserves file order)
- show-tags: Display tag badges under each term (default: false)
- collapsed: Wrap in collapsible <details> element (default: false)
- limit: Show only first N terms with "Show all" expansion (default: all)
- source: Custom glossary file path (default: data/glossary.yaml)
Architecture:
Parse phase records options only. Data loading is deferred to render
phase where renderer._site provides access to site.data and site.root_path.
DirectivePluginMethods 1
parse
Parse glossary directive options.
Note: Data loading is deferred to render pha…
parse
def parse(self, block: Any, m: Match[str], state: Any) -> dict[str, Any]
Parse glossary directive options.
Note: Data loading is deferred to render phase where we have access to site.data via renderer._site.
Parameters 3
block |
Any |
Block parser |
m |
Match[str] |
Regex match object |
state |
Any |
Parser state |
Returns
Token dict with type 'glossary' containing options for render phasedict[str, Any]
—
Internal Methods 3
_parse_bool
Parse boolean option value.
_parse_bool
def _parse_bool(self, value: str | bool) -> bool
Parse boolean option value.
Parameters 1
value |
str | bool |
Returns
bool
_parse_int
Parse integer option value, returns 0 on invalid input.
_parse_int
def _parse_int(self, value: str | int) -> int
Parse integer option value, returns 0 on invalid input.
Parameters 1
value |
str | int |
Returns
int
__call__
Register the directive and renderer.
__call__
def __call__(self, directive: Any, md: Any) -> Any
Register the directive and renderer.
Parameters 2
directive |
Any |
|
md |
Any |
Returns
Any
Functions
render_glossary
Render glossary to HTML as a definition list.
Data loading happens here (deferred from parse phase…
render_glossary
def render_glossary(renderer: Any, text: str, **attrs: Any) -> str
Render glossary to HTML as a definition list.
Data loading happens here (deferred from parse phase) using:
- renderer._site.data.glossary (pre-loaded by Site from data/ directory)
- Fallback: file loading using renderer._site.root_path
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
renderer |
Any |
— | Mistune renderer (has _site attribute with site.data and root_path) |
text |
str |
— | Rendered children content (unused for glossary) **attrs: Glossary attributes from directive (tags, sorted, etc.) |
Returns
HTML string for glossary definition liststr
—
_load_glossary_data
Load glossary data from site.data or file.
Tries these sources in order:
1. site.data.glossary (if…
_load_glossary_data
def _load_glossary_data(renderer: Any, source_path: str) -> dict[str, Any]
Load glossary data from site.data or file.
Tries these sources in order:
- site.data.glossary (if source is default data/glossary.yaml)
- File loading using site.root_path
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
renderer |
Any |
— | Mistune renderer with _site attribute |
source_path |
str |
— | Path to glossary file (default: data/glossary.yaml) |
Returns
Dict with 'terms' key, or 'error' key on failuredict[str, Any]
—
_filter_terms
Filter terms by tags.
A term matches if it has ANY of the requested tags (OR logic).
_filter_terms
def _filter_terms(terms: list[dict[str, Any]], tags: list[str]) -> list[dict[str, Any]]
Filter terms by tags.
A term matches if it has ANY of the requested tags (OR logic).
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
terms |
list[dict[str, Any]] |
— | List of term dicts from glossary |
tags |
list[str] |
— | List of tags to match |
Returns
List of matching termslist[dict[str, Any]]
—
_render_term
Render a single glossary term as dt/dd pair.
_render_term
def _render_term(renderer: Any, term_data: dict[str, Any], show_tags: bool) -> str
Render a single glossary term as dt/dd pair.
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
renderer |
Any |
— | |
term_data |
dict[str, Any] |
— | |
show_tags |
bool |
— |
Returns
str
_parse_inline_markdown
Parse inline markdown in glossary definitions.
Tries to use mistune's inline parser first (proper …
_parse_inline_markdown
def _parse_inline_markdown(renderer: Any, text: str) -> str
Parse inline markdown in glossary definitions.
Tries to use mistune's inline parser first (proper way), falls back to simple regex for basic markdown if not available.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
renderer |
Any |
— | Mistune renderer instance |
text |
str |
— | Text to parse |
Returns
HTML string with inline markdown convertedstr
—
_escape_html
Escape HTML special characters.
_escape_html
def _escape_html(text: str) -> str
Escape HTML special characters.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
— |
Returns
str