Commit e7bf0b9
committed
docs(widgets): survive non-HTML Sphinx builders in the highlight filter
``make_highlight_filter`` dereferenced ``env.app.builder.highlighter``
at filter-registration time, but that attribute only exists on
``StandaloneHTMLBuilder`` and its subclasses. Running
``sphinx-build -b text|linkcheck|gettext|man`` on a page that uses the
``{mcp-install}`` directive crashed with ``AttributeError: 'TextBuilder'
object has no attribute 'highlighter'`` because ``SphinxDirective.run()``
executes during doctree construction for every builder.
The prior comment ("Callers are guaranteed an HTML builder by the
``builder.format == 'html'`` guard in ``install_widget_assets``") was
wrong -- that guard protects only the asset-copy hook, not the render
path.
Fix: narrow via ``isinstance(builder, StandaloneHTMLBuilder)`` (which
also covers DirectoryHTMLBuilder + SingleFileHTMLBuilder). For non-HTML
builders, fall back to an HTML-escaped ``<pre>`` block. The isinstance
narrow eliminates the ``# type: ignore[attr-defined]`` that previously
covered the bare attribute access.
Adds ``test_widget_renders_with_text_builder`` which drives the text
builder end-to-end and would AttributeError before this fix.1 parent 906dc40 commit e7bf0b9
2 files changed
Lines changed: 41 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
119 | 120 | | |
120 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
121 | 129 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
134 | 144 | | |
135 | 145 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
203 | 218 | | |
204 | 219 | | |
205 | 220 | | |
| |||
0 commit comments