How To Add Rel Attribute To Docutils Sphinx Reference In HTML Output?
I have a simple extension for the Sphinx documentation utility (my version in use isSphinx-1.1.3-py2.6). Very much like this excellent example by Doug Hellmann. How can I add a rel
Solution 1:
I managed to do this with download_reference
. Using app.add_node
I override the visit_...
method:
import posixpath
from sphinx.writers.html import HTMLTranslator
from sphinx.addnodes import download_reference
def visit_download_reference(self, node):
if node.hasattr('filename'):
self.body.append(
'<a class="reference download internal" href="%s" %s>' %
(posixpath.join(self.builder.dlpath, node['filename']), 'rel="%s"' % node['rel'] if node.get('rel', None) else ''))
self.context.append('</a>')
else:
self.context.append('')
def setup(app):
app.add_node(download_reference, html=(visit_download_reference, HTMLTranslator.depart_download_reference))
Post a Comment for "How To Add Rel Attribute To Docutils Sphinx Reference In HTML Output?"