Python sphinx 用于引用的自定义sphinx角色
我想创建一个sphinx角色Python sphinx 用于引用的自定义sphinx角色,python-sphinx,docutils,Python Sphinx,Docutils,我想创建一个sphinx角色:config:`param`,它显示为文本config[“param”],同时是一个链接 我有一个基本的运行版本: def config_role(name, rawtext, text, lineno, inliner, options={}, content=[]): rendered = nodes.Text('config["{}"]'.format(text)) rel_source = inliner.document.attribut
:config:`param`
,它显示为文本config[“param”]
,同时是一个链接
我有一个基本的运行版本:
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}
然而,有两个问题:
- 链接的目标位于文档的另一部分。因此,我必须显式地创建
。是否可以像使用.rst中的refuri
那样使用链接锚:ref:`config`
有一个不必要的效果,即双引号被印刷引号替换。因为它是在一个文字块,我宁愿保留简单的双引号。这有可能吗nodes.reference
conf.py
中是否有html\u use\u smartypants=True
或smartquotes=True
设置?Sphinx 1.7.5。这两个变量均未在conf.py
中定义。您需要显式添加它并将其设置为False
。对不起,我不知道关于这个角色的主要问题。我无法解析那个问题。谢谢!在我上面的代码中,是否有某种方法可以暂时关闭该选项(仅针对引用节点)?当使用选项调用sphinx build
时,命令行上的所有配置选项都可能被覆盖。