编程语言
首页 > 编程语言> > python – 在reStructuredText中创建编号列表

python – 在reStructuredText中创建编号列表

作者:互联网

如何在reStructuredText中创建一个编号列表,其中每个项目都是下面某些相应文本的链接?例如,在“常见问题”页面中使用,其中问题被列出并编号为超链接,并且每个问题的链接在页面下面引出其答案.例如:

1. question 1 [links to #1 below]
2. question 2 [links to #2 below]
3. question 3 [links to #3 below]
4. ...

#1 question 1:
the answer to question 1

#2 question 2:
the answer to question 2

#3 question 3:
the answer to question 3

在HTML中,可以使用hrefs和#符号来完成,但我想知道什么是等效的reStructuredText语法?

解决方法:

请参阅第一个Google结果中的“重组文本列表”中的enumerated listsinternal hyperlink targets.您可以将它们组合起来:

#. `question 1`_
#. `question 2`_

.. _question 1:
the answer to question 1

对于每条评论的反向引用,您可以使用“inline internal targets”,快速参考提及但只有完整参考实际描述.不幸的是,同一个文本似乎不可能既是一个链接又是一个目标(即使语法在技术上允许它,它也是不明确的),所以你需要列表项中的更多文本而不仅仅是问题.您最好的方法可能是将每个问题链接回列表而不是特定的列表项 – 例如,

.. _List of questions:
...

.. _question 1:
the answer to question 1
`List of questions`_

标签:python,python-sphinx,restructuredtext
来源: https://codeday.me/bug/20190726/1538654.html