Interlinks filter
The interlinks filter allows you to provide crossreferences within and between documentation. It consists of three pieces:
- Install: adding the extension to your quarto project.
- Configure: specifying sphinx inventories for the filter to use in your
_quarto.ymlconfig. - Run: Generating sphinx inventories for the filter to use.
Installing
Use the quarto add command to install the interlinks filter:
quarto add machow/quartodocThe code for the filter can be found in quartodoc’s _extension folder
Configuring the interlinks filter
Configure the filter in _quarto.yml or on specific pages, by adding these sections:
filters:
- interlinks
interlinks:
sources:
numpy:
url: https://numpy.org/doc/stable/
python:
url: https://docs.python.org/3/
quartodoc-test:
url: https://machow.github.io/quartodoc
inv: objects-test.txtNotice 2 important pieces in this config:
- The
numpyandpythonfields indicate that we’re getting inventories for the library numpy, and python builtin libraries. - The
urlfields indicate where inventory files can be found. - The
invfield lets you specify the name of the inventory file. By default, it assumes itsobjects.inv.
By default, downloaded inventory files will be saved in the _inv folder of your documentation directory.
Experimental fast option
Use the experimental fast: true option to speed up the interlinks filter.
interlinks:
fast: true
sources:By default inventory files are saved as JSON, but this option keeps them as text files, and attempts to parse them much faster.
Be sure to install the latest version of the interlinks filter, using quarto add machow/quartodoc.
Rendering interlinks in API docs
quartodoc can convert type annotations in function signatures to interlinks.
In order to enable this behavior, set render_interlinks: true in the quartodoc config.
quartodoc:
render_interlinks: trueRunning the interlinks filter
First, build the reference for your own site, which includes an objects.json inventory:
python -m quartodoc buildSecond, retrieve the inventory files for any other sources:
python -m quartodoc interlinksFinally you should see the filter run when previewing your docs:
quarto previewLink formats
| style | link text | syntax | output |
|---|---|---|---|
| manual | [a link](../api/#get_object) |
a link | |
| md | custom | [some explanation](`quartodoc.get_object`) |
some explanation |
| md | default | [](`quartodoc.get_object`) |
quartodoc.get_object |
| md | shortened | [](`~quartodoc.get_object`) |
get_object |
Link aliases
Use interlinks.aliases in _quarto.yml to refer to functions without their module name (or using a shortened version of it).
For example the following config sets aliases for quartodoc and pandas:
interlinks:
aliases:
quartodoc: null
pandas: pdIn this case, you can refer to quartodoc.get_object as get_object, and pandas.DataFrame as pd.DataFrame.
Link filtering syntax
Sometimes multiple documentation sites use the same target (e.g. function) names. The inventory format includes multiple pieces of information that can be used to refer to a specific entry in the inventory:
inventory_namerole: what kind of object is it? e.g. function, class.domain: what kind of piece of documentation is it? For example,"py"indicates it is a python function, and"c"indicates it’s a C function. This lets sites document libraries that are implemented in multiple languages.
Filtering by these pieces of information can be down using the following syntax:
:external+inventory_name:domain:role:`target`
:domain:role:`target`
:role:`target`
`target`Notice that this syntax allows you to go from more specific information (i.e. `target` on the right), to least specific information (role, then domain).
In practice, it’s often enough to specify the role of a function, like:
:function:`quartodoc.get_object`:class:`quartodoc.MdRenderer`
Example: python.org print
For example, python.org has two entries for the name print.
| domain | role | link syntax |
|---|---|---|
| std | 2to3fixer | [](:std:2to3fixer:`print`) |
| py | function | [](:py:function:`print`) |
What is a sphinx inventory file?
Sphinx inventory files provide information about where the documentation for functions live on a website.
Most sphinx sites name them object.inv:
- numpy: https://numpy.org/doc/stable/objects.inv
- python: https://docs.python.org/3/objects.inv
See the sphobjinv docs for thorough details on these files, and how they’re used in sphinx.
objects-test.txt is an example file with one entry: qd2.Auto.
More information
Under the hood, quarto doc generates sphinx inventories for an API e using create_inventory, and then dumps it to JSON using convert_inventory.
For an overview of the sphinx inventory format, see the sphobjinv docs.
The rough idea is that this plugin will behave similar to jupyterbook linking, which supports both some intersphinx syntax, but also markdown syntax.