sphinx.ext.linkcode – 为源代码添加外部链接¶
模块作者: Pauli Virtanen
Added in version 1.2.
此扩展查看您的对象描述( .. class :: , .. function:: 等),并添加指向托管在网络上的代码的外部链接.其意图类似于 sphinx.ext.viewcode 扩展,但假设源代码可以在互联网上找到.
在配置中,您需要指定一个 linkcode_resolve 函数,该函数根据对象返回一个 URL.
配置¶
- linkcode_resolve¶
这是一个函数
linkcode_resolve(domain, info),它应该返回与给定域和给定信息中对象对应的源代码的 URL.如果没有要添加的链接,函数应返回
None.参数
domain指定对象所在的语言域.info是一个字典,保证包含以下键(取决于域):py:module(name of the module),fullname(name of the object)c:names(list of names for the object)cpp:names(list of names for the object)javascript:object(name of the object),fullname(name of the item)
示例:
def linkcode_resolve(domain, info): if domain != 'py': return None if not info['module']: return None filename = info['module'].replace('.', '/') return "https://somesite/sourcerepo/%s.py" % filename