summaryrefslogtreecommitdiff
path: root/docs/rstjinja.py
blob: 3a08b2599771bfd37d3451ac906e126b5833de3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Derived from code on Eric Holscher's blog, found at:
# https://www.ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinx/

def rstjinja(app, docname, source):
    """
    Render our pages as a jinja template for fancy templating goodness.
    """
    # Make sure we're outputting HTML
    if app.builder.format != 'html':
        return

    # we only want our one jinja template to run through this func
    if "shared-bindings/support_matrix" not in docname:
        return

    src = source[0]
    print(docname)
    rendered = app.builder.templates.render_string(
        src, app.config.html_context
    )
    source[0] = rendered

def setup(app):
    app.connect("source-read", rstjinja)