|
17 | 17 | #
|
18 | 18 | # SPDX-License-Identifier: MIT
|
19 | 19 |
|
20 |
| -import json |
21 | 20 | import logging
|
22 | 21 | import os
|
23 | 22 | import subprocess
|
24 | 23 | import sys
|
25 | 24 | import urllib.parse
|
26 | 25 |
|
27 | 26 | import recommonmark
|
| 27 | +from sphinx.transforms import SphinxTransform |
| 28 | +from docutils import nodes |
| 29 | +from sphinx import addnodes |
28 | 30 |
|
29 | 31 | # If extensions (or modules to document with autodoc) are in another directory,
|
30 | 32 | # add these directories to sys.path here. If the directory is relative to the
|
|
84 | 86 | autoapi_add_toctree_entry = False
|
85 | 87 | autoapi_options = ['members', 'undoc-members', 'private-members', 'show-inheritance', 'special-members', 'show-module-summary']
|
86 | 88 | autoapi_template_dir = 'docs/autoapi/templates'
|
| 89 | +autoapi_python_class_content = "both" |
87 | 90 | autoapi_python_use_implicit_namespaces = True
|
88 | 91 | autoapi_root = "shared-bindings"
|
89 | 92 |
|
@@ -423,7 +426,38 @@ def generate_redirects(app):
|
423 | 426 | with open(redirected_filename, 'w') as f:
|
424 | 427 | f.write(TEMPLATE % urllib.parse.quote(to_path, '#/'))
|
425 | 428 |
|
| 429 | + |
| 430 | +class CoreModuleTransform(SphinxTransform): |
| 431 | + default_priority = 870 |
| 432 | + |
| 433 | + def _convert_first_paragraph_into_title(self): |
| 434 | + title = self.document.next_node(nodes.title) |
| 435 | + paragraph = self.document.next_node(nodes.paragraph) |
| 436 | + if not title or not paragraph: |
| 437 | + return |
| 438 | + if isinstance(paragraph[0], nodes.paragraph): |
| 439 | + paragraph = paragraph[0] |
| 440 | + if all(isinstance(child, nodes.Text) for child in paragraph.children): |
| 441 | + for child in paragraph.children: |
| 442 | + title.append(nodes.Text(" \u2013 ")) |
| 443 | + title.append(child) |
| 444 | + paragraph.parent.remove(paragraph) |
| 445 | + |
| 446 | + def _enable_linking_to_nonclass_targets(self): |
| 447 | + for desc in self.document.traverse(addnodes.desc): |
| 448 | + for xref in desc.traverse(addnodes.pending_xref): |
| 449 | + if xref.attributes.get("reftype") == "class": |
| 450 | + xref.attributes.pop("refspecific", None) |
| 451 | + |
| 452 | + def apply(self, **kwargs): |
| 453 | + docname = self.env.docname |
| 454 | + if docname.startswith(autoapi_root) and docname.endswith("/index"): |
| 455 | + self._convert_first_paragraph_into_title() |
| 456 | + self._enable_linking_to_nonclass_targets() |
| 457 | + |
| 458 | + |
426 | 459 | def setup(app):
|
427 | 460 | app.add_css_file("customstyle.css")
|
428 | 461 | app.add_config_value('redirects_file', 'redirects', 'env')
|
429 | 462 | app.connect('builder-inited', generate_redirects)
|
| 463 | + app.add_transform(CoreModuleTransform) |
0 commit comments