How to create referenceable label node above section in sphinx(如何在Shinx中创建可引用的标签节点)
本文介绍了如何在Shinx中创建可引用的标签节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用Shinx创建自定义指令。 此指令列出了所有可能的对象(每个对象都在单独的部分中)。
现在,我希望文档的其他部分(文件)可以引用这些对象。
我想做一些非常简单的事情,比如:
class MyDirective(Directive):
def run(self, obj):
id1 = 'object-unique-id1'
id2 = 'object-unique-id2'
label = nodes.label('abc1', refid=id1)
section = nodes.section(ids=[id2])
section += nodes.title(text='abc')
section += label
return [section]
但它不允许我通过:ref:object-unique-id1
、:ref:object-unique-id2
或:ref:abc
引用此部分。
所以我的问题是:如何创建可以引用的节点?
推荐答案
在节前添加目标似乎有效。类似于:
class MyDirective(Directive):
def run(self, obj):
titleTxt = 'abc'
lineno = self.state_machine.abs_line_number()
target = nodes.target()
section = nodes.section()
# titleTxt appears to need to be same as the section's title text
self.state.add_target(titleTxt, '', target, lineno)
section += nodes.title(titleTxt, '')
return [target, section]
注意对self.state.add_target
的调用。
在构建稍后的某个地方,目标会被魔术般地创建,并且应该能够用
引用您的部分:ref:`abc`
项目中的任何位置。
这篇关于如何在Shinx中创建可引用的标签节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何在Shinx中创建可引用的标签节点


猜你喜欢
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01