I would like to create a sphinx role :config:`param`
that appears as literal text config["param"]
and at the same time is a link.
I've a basic running version:
def config_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
rendered = nodes.Text('config["{}"]'.format(text))
rel_source = inliner.document.attributes['source'].split('/doc/', 1)[1]
levels = rel_source.count('/')
refuri = ('../' * levels +
'tutorials/introductory/customizing.html#config')
ref = nodes.reference(rawtext, rendered, refuri=refuri)
return [nodes.literal('', '', ref)], []
def setup(app):
app.add_role("config", config_role)
return {"parallel_read_safe": True, "parallel_write_safe": True}
However, there are two issues:
- The target of the link is in another part of the documentation. Therefore I have to create the
refuri
explicitly. Is is possible to use the link anchor somehow as one would do with:ref:`config`
in .rst? nodes.reference
has the unwanted effect that the double-quotes are replaced by typographic quotes. Since it's in a literal bock, I'd rather keep the plain double quotes. Is this somehow possible?