feat: Allow extensions to add templates #569
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An extension here is simply a Python package that defines an entry-point for a specific handler.
For example, an extension can add templates to the Python handler thanks to this entry-point:
This entry-point assumes that the extension provides a
get_templates_path
function directly under theextension_package
package. This function doesn't accept any argument and returns the path to a directory containing templates. The directory must contain one subfolder for each supported theme, for example:mkdocstrings will add the folders corresponding to the user-selected theme, and to the handler's defined fallback theme, as usual.
The names of the extension templates must not overlap with the handler's original templates.
The extension is then responsible, in collaboration with its target handler, for mutating the collected data in order to instruct the handler to use one of the extension template when rendering particular objects.
For example, the Python handler will look for a
template
attribute on objects, and use it to render the object. Thistemplate
attribute will be set by Griffe extensions (Griffe is the tool used by the Python handler to collect data).See related PR: mkdocstrings/python#70
TODO