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匹配Stata加权xtil命令的确定方法? 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01