Skip to main content
https://github.com/tardyp/sphinx-jinja/actions/workflows/ci.yml/badge.svg

sphinx-jinja

A sphinx extension to include jinja based templates based documentation into a sphinx doc

Usage

In your rst doc, you can use the following snippet to use a jinja template to generate your doc

.. jinja:: first_ctx

    {% for k, v in topics.items() %}

    {{k}}
    ~~~~~
    {{v}}
    {% endfor %}

In your sphinx conf.py file, you can create or load the contexts needed for your jinja templates

extensions = ['sphinx_jinja']

jinja_contexts = {
    'first_ctx': {'topics': {'a': 'b', 'c': 'd'}}
}

You can also customize the jinja Environment by passing custom kwargs, adding filters, tests, and globals, and setting policies:

jinja_env_kwargs = {
    'lstrip_blocks': True,
}

jinja_filters = {
    'bold': lambda value: f'**{value}**',
}

jinja_tests = {
    'instanceof': lambda value, type: isinstance(value, type),
}

jinja_globals = {
    'list': list,
}

jinja_policies = {
    'compiler.ascii_str': False,
}

Which can then be used in the templates:

Lists
-----

{% for o in objects -%}
    {%- if o is instanceof list -%}
        {%- for x in o -%}
            - {{ x|bold }}
        {% endfor -%}
    {%- endif -%}
{%- endfor %}

Available options

  • file: allow to specify a path to Jinja instead of writing it into the content of the directive. Path is relative to the current directory of sphinx-build tool, typically the directory where the conf.py file is located.

  • header_char: character to use for the the headers. You can use it in your template to set your own title character:

    For example:

    Title
    {{ options.header_char * 5 }}
  • header_update_levels: If set, a header in the template will appear as the same level as a header of the same style in the source document, equivalent to when you use the include directive. If not set, headers from the template will be in levels below whatever level is active in the source document.

  • debug: print debugging information during sphinx-build. This allows you to see the generated rst before sphinx builds it into another format.

Example of declaration in your RST file:

.. jinja:: approval_checks_api
   :file: relative/path/to/template.jinja
   :header_char: -

Each element of the jinja_contexts dictionary is a context dict for use in your jinja templates.

Running tests

  • pip install tox

  • tox

Metadata

Release files for sphinx-jinja 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-jinja 2.0.2
File Size Uploaded Provenance
sphinx-jinja-2.0.2.tar.gz 4.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-jinja 2.0.2
File Interpreter ABI Platform
sphinx_jinja-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.9 kB

Release files / sphinx-jinja-2.0.2.tar.gz

Download URL sphinx-jinja-2.0.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c6232b59a894139770be1dc6d0b00a379e4288ce78157904e1f8473dea3e0718
BLAKE2b-256 checksum
How to use checksums
ea907cf0e91aadcb5b3ff4796acbaf2c7887a55434df360914af9fc067c753c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / sphinx_jinja-2.0.2-py3-none-any.whl

Download URL sphinx_jinja-2.0.2-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
705ebeb9b7a6018ca3f93724315a7c1effa6ba3db44d630e7eaaa15e4ac081a8
BLAKE2b-256 checksum
How to use checksums
209f81fe50b1861bda8c02b4272a166d14455411e04865ddaf3616f25d12cd50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for sphinx-jinja 2.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page