| 1 |
{#- Template for docstrings. |
| 2 |
|
| 3 |
This template renders Python docstrings. |
| 4 |
Griffe parses docstrings into a list of sections, each with a `kind` and a `value`. |
| 5 |
This template can then iterate on these sections and render them according to the configuration. |
| 6 |
|
| 7 |
Context: |
| 8 |
docstring_sections (list[griffe.DocstringSection]): The list of docstring sections. |
| 9 |
config (dict): The configuration dictionary. |
| 10 |
heading_level (int): The heading level to use for Markdown conversion. |
| 11 |
html_id (str): The HTML ID to use for Markdown conversion. |
| 12 |
-#} |
| 13 |
|
| 14 |
{% if docstring_sections %} |
| 15 |
{% block logs scoped %} |
| 16 |
{#- Logging block. |
| 17 |
|
| 18 |
This block can be used to log debug messages, deprecation messages, warnings, etc. |
| 19 |
-#} |
| 20 |
{{ log.debug("Rendering docstring") }} |
| 21 |
{% endblock logs %} |
| 22 |
{% with autoref_hook = AutorefsHook(obj, config) %} |
| 23 |
{% for section in docstring_sections %} |
| 24 |
{% if config.show_docstring_description and section.kind.value == "text" %} |
| 25 |
{{ section.value|convert_markdown(heading_level, html_id, autoref_hook=autoref_hook) }} |
| 26 |
{% elif config.show_docstring_attributes and section.kind.value == "attributes" %} |
| 27 |
{% include "docstring/attributes.html.jinja" with context %} |
| 28 |
{% elif config.show_docstring_functions and section.kind.value == "functions" %} |
| 29 |
{% include "docstring/functions.html.jinja" with context %} |
| 30 |
{% elif config.show_docstring_classes and section.kind.value == "classes" %} |
| 31 |
{% include "docstring/classes.html.jinja" with context %} |
| 32 |
{% elif config.show_docstring_type_aliases and section.kind.value == "type aliases" %} |
| 33 |
{% include "docstring/type_aliases.html.jinja" with context %} |
| 34 |
{% elif config.show_docstring_modules and section.kind.value == "modules" %} |
| 35 |
{% include "docstring/modules.html.jinja" with context %} |
| 36 |
{% elif config.show_docstring_type_parameters and section.kind.value == "type parameters" %} |
| 37 |
{% include "docstring/type_parameters.html.jinja" with context %} |
| 38 |
{% elif config.show_docstring_parameters and section.kind.value == "parameters" %} |
| 39 |
{% include "docstring/parameters.html.jinja" with context %} |
| 40 |
{% elif config.show_docstring_other_parameters and section.kind.value == "other parameters" %} |
| 41 |
{% include "docstring/other_parameters.html.jinja" with context %} |
| 42 |
{% elif config.show_docstring_raises and section.kind.value == "raises" %} |
| 43 |
{% include "docstring/raises.html.jinja" with context %} |
| 44 |
{% elif config.show_docstring_warns and section.kind.value == "warns" %} |
| 45 |
{% include "docstring/warns.html.jinja" with context %} |
| 46 |
{% elif config.show_docstring_yields and section.kind.value == "yields" %} |
| 47 |
{% include "docstring/yields.html.jinja" with context %} |
| 48 |
{% elif config.show_docstring_receives and section.kind.value == "receives" %} |
| 49 |
{% include "docstring/receives.html.jinja" with context %} |
| 50 |
{% elif config.show_docstring_returns and section.kind.value == "returns" %} |
| 51 |
{% include "docstring/returns.html.jinja" with context %} |
| 52 |
{% elif config.show_docstring_examples and section.kind.value == "examples" %} |
| 53 |
{% include "docstring/examples.html.jinja" with context %} |
| 54 |
{% elif config.show_docstring_description and section.kind.value == "admonition" %} |
| 55 |
{% include "docstring/admonition.html.jinja" with context %} |
| 56 |
{% endif %} |
| 57 |
{% endfor %} |
| 58 |
{% endwith %} |
| 59 |
{% endif %} |