A MkDocs plugin that generates Sphinx-compatible objects.inv files for intersphinx cross-referencing.
- Page-level references via YAML frontmatter
- Header-level references via HTML comments
- Generates Sphinx-compatible
objects.invfiles
From the plugin directory:
pip install -e .Or with development dependencies:
pip install -e ".[dev]"Add to your mkdocs.yml:
plugins:
- search
- intersphinx:
enabled: true
project: "My Project"
version: "latest"---
ref: my-page-reference
title: My Page Title
---
# My Page
Content here...# My Page
<!-- ref:important-section -->
## Important Section
This section can be referenced by other projects.
<!-- ref:another-topic -->
### Another Topic
More content...mkdocs buildThe plugin will generate site/objects.inv containing all references.
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
bool | true |
Enable/disable the plugin |
project |
str | site_name | Project name for the inventory |
version |
str | "latest" |
Project version |
output |
str | "objects.inv" |
Output filename |
domain |
str | "std" |
Sphinx domain for entries |
page_role |
str | "doc" |
Role for page references |
header_role |
str | "label" |
Role for header references |
verbose |
bool | false |
Enable verbose logging |
In your Sphinx conf.py:
intersphinx_mapping = {
'myproject': ('https://example.com/docs/', None),
}Reference in reStructuredText:
See :doc:`myproject:my-page-reference`
See :ref:`myproject:important-section`In your mkdocs.yml:
plugins:
- mkdocstrings:
handlers:
python:
import:
- https://example.com/docs/objects.invpytestpytest --cov=mkdocs_intersphinx --cov-report=html- Parse Phase (
on_page_markdown): Extract HTML ref comments and parse headers - Collection Phase (
on_page_content): Collect inventory entries with actual anchor IDs from TOC - Generation Phase (
on_post_build): Create and writeobjects.invfile usingsphobjinv
- Use lowercase letters, numbers, hyphens, and underscores only
- Use hyphens to separate words (e.g.,
thread-safety-levels) - Make names descriptive but concise
- Ensure names are unique across your documentation
See the tests/ directory for example usage.
MIT
Contributions welcome! Please open an issue or pull request.