add_ai_assistant_context#

scikitplot._externals._sphinx_ext._sphinx_ai_assistant.add_ai_assistant_context(app, pagename, templatename, context, doctree)[source]#

Inject AI-assistant configuration into each HTML page’s template context.

Registered with Sphinx’s html-page-context event in setup.

Parameters:
appsphinx.application.Sphinx

The active Sphinx application instance.

pagenamestr

The logical page name (e.g. "index").

templatenamestr

The Jinja2 template name (e.g. "page.html").

contextdict

The template rendering context; modified in place.

doctreedocutils.nodes.document or None

The parsed document tree for the page.

Returns:
None
Parameters:
  • app (Sphinx)

  • pagename (str)

  • templatename (str)

  • context (Dict[str, Any])

  • doctree (Any)

Return type:

None

Notes

Security: The configuration dict is serialised with _safe_json_for_script which escapes </script> sequences, preventing script-injection attacks via adversarially crafted config values.

Position validation: ai_assistant_position is validated against _ALLOWED_POSITIONS. Invalid values are replaced with "sidebar" and a warning is logged.

Provider filtering: Providers whose url_template does not use the http:// or https:// scheme are silently removed from the serialised config to prevent javascript: or data: injection via the browser-side widget.