Skip to content

@shimizukawa /conf.py
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
sphinx: doc reference by using substitution and custome 'doc' inline directive. inspired by https://bitbucket.org/birkenfeld/sphinx/issue/1077
############################################
# inline doc directive for substitution
# rst: .. |sub| doc:: docname
# html: <a href="docname.html">sub</a>
from sphinx.util.compat import Directive
from sphinx.roles import XRefRole
class DocDirective(Directive):
required_arguments = 1
def run(self):
docname = self.arguments[0]
text = self.state.parent['names'][0]
rawtext = "%s <%s>" % (text, docname)
return XRefRole(warn_dangling=True)(
'doc', rawtext, rawtext, self.state.parent.line, self.state)[0]
def setup(app):
app.add_directive('doc', DocDirective)
<p>This is link to <a class="reference internal" href="foo.html"><em>The Foo</em></a> by using substitution.</p>
This is link to |The Foo| by using substitution.
.. |The Foo| doc:: foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.