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-contextevent insetup.- 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:
- Return type:
None
Notes
Security: The configuration dict is serialised with
_safe_json_for_scriptwhich escapes</script>sequences, preventing script-injection attacks via adversarially crafted config values.Position validation:
ai_assistant_positionis validated against_ALLOWED_POSITIONS. Invalid values are replaced with"sidebar"and a warning is logged.Provider filtering: Providers whose
url_templatedoes not use thehttp://orhttps://scheme are silently removed from the serialised config to preventjavascript:ordata:injection via the browser-side widget.