def render_widgets(kb_app: kb,
                   sphinx_app: Sphinx,
                   doctree: doctree,
                   fromdocname: str,
                   ):
    """ Go through docs and replace widget directive with rendering """

    builder: StandaloneHTMLBuilder = sphinx_app.builder

    for node in doctree.traverse(widget):
        # Render the output
        w = sphinx_app.env.widgets.get(node.name)
        context = builder.globalcontext.copy()

        # Add in certain globals
        context['resources'] = sphinx_app.env.resources
        context['references'] = sphinx_app.env.references
        output = w.render(sphinx_app, context)

        # Put the output into the node contents
        listing = [nodes.raw('', output, format='html')]
        node.replace_self(listing)