config: add classlink directive

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.
This commit is contained in:
Laurens Valk
2021-02-14 15:39:39 +01:00
parent 109fcf19c1
commit 4a7fa12eaa
7 changed files with 62 additions and 60 deletions
+1
View File
@@ -59,6 +59,7 @@ extensions = [
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'color',
'classlink',
]
# Add any paths that contain templates here, relative to this directory.
+31
View File
@@ -0,0 +1,31 @@
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)