mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 01:24:17 +00:00
We have index pages for most modules now, which link to individual classes. It is helpful if these empty class headers are hyperlinks. This commit does just that. For most sensors/devices so far this is not really necessary as the images are already hyperlinks. But this will become more useful as we start adding index pages like these for classes without images, such as parameters.
32 lines
799 B
Python
32 lines
799 B
Python
from docutils import nodes
|
|
from docutils.parsers.rst import Directive
|
|
|
|
|
|
class PybricksClasslinkDirective(Directive):
|
|
|
|
required_arguments = 1
|
|
|
|
def run(self):
|
|
# Get link name from sphinx-directive
|
|
name = self.arguments[0]
|
|
|
|
html = (
|
|
'<a href="{0}.html">'.format(name.lower()) +
|
|
'<dl class="py class">' +
|
|
'<dt>' +
|
|
'<em class="property">class </em>' +
|
|
'<code class="sig-name descname">' + name + '</code>' +
|
|
'</dt>' +
|
|
'<dd></dd>' +
|
|
'</dl>' +
|
|
'</a>'
|
|
)
|
|
|
|
# Return the node
|
|
node = nodes.raw('', html, format="html")
|
|
return [node]
|
|
|
|
|
|
def setup(app):
|
|
app.add_directive_to_domain('py', 'pybricks-classlink', PybricksClasslinkDirective)
|