Files
PraisonAIUI/docs_hooks.py
MervinPraison 3a10f48632 feat: close extensibility gaps + hotfix 0.3.108
Closes 5 documented gaps from how-to-add-a-feature.md:

- aiui.set_custom_js(path) — inject client JS from Python (new /custom.js route, <script> after plugin-loader). Tests: 10/10
- name= kwarg on all 8 form inputs — stable submit-keys for form_action, avoids label collisions. Tests: 18/18
- Component schema registry — aiui.register_component_schema() + GET /api/components/schemas. Built-in schemas auto-derived from ui.py. Tests: 9/9
- /api/features parallelized via asyncio.gather (warm calls now instant)
- mkdocs build fixed for pygments 2.20 via docs_hooks.py

Other:
- form inputs now emit name + data-label attrs so form_action submit handler collects values correctly (bug fix)
- radio submit handler only stores the checked radio's value
- switch now has hidden checkbox mirror so form_action sees its state
- mkdocs --strict passes
- Example 28 uses the new APIs (no more DevTools console workaround)
- Bump aiui 0.3.107 -> 0.3.108; sync __version__.py

Tests: 542/545 pass (3 pre-existing test-isolation failures unrelated).
2026-04-19 02:36:38 +01:00

45 lines
1.3 KiB
Python

"""mkdocs hook: patch pymdownx.highlight for pygments >= 2.20 compatibility.
Pygments 2.20 removed tolerance for ``filename=None`` in HtmlFormatter,
which pymdownx.highlight can pass when a code fence has no ``title``.
Without this patch, ANY untitled ```python``` block triggers::
AttributeError: 'NoneType' object has no attribute 'replace'
Reference: https://github.com/facelessuser/pymdown-extensions/issues/XXXX
This is a drop-in fix: normalize ``filename`` to an empty string.
"""
from __future__ import annotations
def _patch_pymdownx_highlight() -> None:
try:
from pymdownx import highlight as _hi # type: ignore
except Exception:
return
if getattr(_hi, "_aiui_patched", False):
return
_orig_init = _hi.BlockHtmlFormatter.__init__
def patched_init(self, **options): # type: ignore
if options.get("filename") is None:
options["filename"] = ""
_orig_init(self, **options)
_hi.BlockHtmlFormatter.__init__ = patched_init
_hi._aiui_patched = True
# Apply immediately when this module is loaded
_patch_pymdownx_highlight()
# mkdocs hook interface: provide at least one expected hook so mkdocs loads us.
def on_config(config, **kwargs):
_patch_pymdownx_highlight()
return config