mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 09:37:25 +00:00
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:
@@ -59,6 +59,7 @@ extensions = [
|
||||
'sphinx.ext.todo',
|
||||
'sphinx.ext.mathjax',
|
||||
'color',
|
||||
'classlink',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user