首页 > 解决方案 > 可以将 Sphinx 设置为根据标题编号(而非文本)自动创建书签吗?

问题描述

我有一个很大的错误参考手册,它正在被转换以便使用 Sphinx 托管在 readthedocs 上。我希望能够使用基于节号(不是标题文本)的永久书签来推荐用户,因为这是软件错误代码中返回的内容。我有类似的东西:

This has a chapter heading automatically numbered to give 1.
============================================================

This has a section heading automatically numbered to give 1.1
-------------------------------------------------------------

- This has no section heading as it's in a list, but is ideally 
where I want to send people using the number 1.1.1.  If that's 
too tricky, then a link to the number of the section (1.1) is fine.

我希望能够根据部分的number自动生成书签,而不是其标题文本:

You got error code 1.1.1 so you need to go to:
www.mysite.readthedocs.io/blah/blah.html#bookmark1.1

有谁知道是否/如何在不为每个部分手动创建自定义书签的情况下实现这一点?提前致谢 :)

PS - 意味着我需要知道自动编号的部分编号将不起作用的建议(例如:Anchor replace with '#id1' , '#id2' , '#id3' ... Sphinx

标签: python-sphinxrestructuredtext

解决方案


不确定我是否完全理解这些要求,但对我来说,这个:numref:角色在这种情况下可能会有所帮助。

.. toctree::
    :numbered:
.. _ping:

Ping
====

See :numref:`section "{name}" ({number}) <ping>`.


.. _pong:

Pong
====

See :numref:`section "{name}" ({number}) <pong>`.


推荐阅读