click_extra.sphinx.theme_docs module¶
Render a theme palette as an inline-styled HTML fragment for documentation.
palette_html() is called from docs/theme.md to render every
built-in theme’s palette at Sphinx build time.
inject_slot_example_docstring() is registered as a Sphinx
autodoc-process-docstring hook from docs/conf.py to inject a colored
example into each HelpTheme slot’s autodoc block. This is build-time
documentation code, kept out of the runtime theme module.
- click_extra.sphinx.theme_docs.inject_slot_example_docstring(app, what, name, obj, options, lines)[source]¶
Sphinx
autodoc-process-docstringhook injecting per-slot colored examples.For every
HelpThemeslot that has an entry in_PALETTE_EXAMPLES, append anansi-colorcode block to the slot’s autodoc lines. The example is rendered through_render_slot_ansi, which callsBUILTIN_THEMES["dark"].<slot>(text)to obtain the actual ANSI escapes click-extra would emit at runtime.Wire this up from a Sphinx
conf.pywith:from click_extra.sphinx.theme_docs import inject_slot_example_docstring def setup(app): app.connect("autodoc-process-docstring", inject_slot_example_docstring)
The hook intentionally targets only
click_extra.theme.HelpTheme.<slot>names so it won’t accidentally rewrite unrelated docstrings; downstream projects can register the hook in their ownconf.pyif they consume HelpTheme docstrings.- Return type:
- click_extra.sphinx.theme_docs.palette_html(theme)[source]¶
Render a theme’s palette as an inline-styled HTML
<dl>fragment.The output is a two-column definition list (slot name → styled swatch plus attribute decorations) safe to inject into MyST or reST host documents via the
python:renderSphinx directive (or anyraw:: htmlblock). Used bydocs/theme.mdto render every built-in theme’s palette at Sphinx build time without hand-maintaining swatch tables. Downstream projects with their own custom themes can call the same helper to get matching swatch listings in their own docs:```{python:render} from click_extra.sphinx.theme_docs import palette_html from my_app.themes import MY_THEME print(palette_html(MY_THEME)) ```Slots that hold
identity(no styling applied), the booleancross_ref_highlighttoggle, and a handful of inherited cloup slots that built-ins never style are skipped: every emitted row corresponds to a real palette choice in the theme.- Return type: