scikitplot._externals#
User guide. See the Externals (experimental) section for further details.
Sphinx extensions.#
scikitplot._externals._sphinx_ext#
Private namespace for vendored Sphinx extensions.
All child submodules are loaded lazily: importing this package does not pull in Sphinx, BeautifulSoup, markdownify, or any other heavy dependency.
Submodules#
- _sphinx_ai_assistant
AI-assistant Sphinx extension (markdown export, llms.txt, AI chat links). Copied and adapted from
mlazag/sphinx-ai-assistant(MIT licence). Requires Sphinx ≥ 5 at call time, not at import time.
Notes
To register the AI-assistant extension in a Sphinx project, add the full
dotted path to extensions in conf.py:
extensions = [
"scikitplot._externals._sphinx_ext._sphinx_ai_assistant",
]
Examples
>>> # Safe: no Sphinx needed yet
>>> from scikitplot._externals import _sphinx_ext
>>> # Sphinx imported here, on demand:
>>> ai = _sphinx_ext._sphinx_ai_assistant
User guide. See the Sphinx Ext (experimental) section for further details.
Sphinx AI Assistant Extension |
Sphinx extensions.#
Sphinx AI Assistant Extension#
A Sphinx extension that adds AI-assistant features to documentation pages,
including one-click Markdown export, AI chat deep-links, MCP tool
integration, and automated llms.txt generation.
All heavy optional dependencies (sphinx, bs4, markdownify) are
imported lazily — only when a feature is actually invoked. Importing
this module at the top level is always safe and has no side effects.
Public API#
- setupcallable
Sphinx extension entry point. Called automatically by Sphinx when this module is listed in
conf.py extensions.
Notes
Developer note — import discipline:
Every import of sphinx.*, bs4, and markdownify lives inside
the function that needs it, guarded by a try/except where appropriate.
Nothing is imported at module scope except stdlib modules. This keeps
import time cost near zero and avoids ImportError at load time when
optional packages are absent.
Security note:
_safe_json_for_scriptescapes</script>sequences to prevent script-injection attacks when config is serialised into an HTML page._is_path_withinprevents path-traversal attacks in the multi-process HTML walker._validate_base_urlrejects non-HTTP(S) schemes in the base URL configuration value._validate_positionrejects unknown widget-position strings._validate_provider_url_templaterejects non-HTTP(S) schemes in AI-provider URL templates, blockingjavascript:anddata:vectors._validate_css_selectorrejects selectors containing HTML-injection characters (<or>).ai_assistant_providersURL templates are validated before use, and unsafe entries are silently dropped from the serialised page config.
References
Examples
Register in conf.py:
extensions = [
"scikitplot._externals._sphinx_ext._sphinx_ai_assistant",
]
html_theme = "pydata_sphinx_theme" # scikit-learn / NumPy style
ai_assistant_enabled = True
ai_assistant_theme_preset = "pydata_sphinx_theme" # auto-selects CSS selectors
ai_assistant_generate_markdown = True
ai_assistant_generate_llms_txt = True
html_baseurl = "https://docs.example.com"
User guide. See the Sphinx AI Extensions (experimental) section for further details.
Inject AI-assistant configuration into each HTML page's template context. |
|
Post-build hook: write |
|
Post-build hook: generate |
|
Convert an HTML string to Markdown using the Sphinx-tuned converter. |