简体   繁体   English

在reStructuredText中创建编号列表

[英]Making numbered lists in reStructuredText

How can I make a numbered list in reStructuredText where each item is a link to some corresponding text below? 如何在reStructuredText中创建一个编号列表,其中每个项目都是下面某些相应文本的链接? For example for use in an "FAQ" page, where the questions are listed and numbered as hyperlinks and each question's link leads to its answer below on the page. 例如,在“常见问题”页面中使用,其中问题被列出并编号为超链接,并且每个问题的链接在页面下面引出其答案。 For example: 例如:

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

In HTML this can be done with hrefs and the # symbol, but I'm wondering what is the equivalent reStructuredText syntax? 在HTML中,可以使用hrefs#符号来完成,但我想知道什么是等效的reStructuredText语法?

A good example to start with is the Docutils FAQ (reStructuredText was developed along side Docutils and Sphinx is simply an extension of Docutils). 一个很好的例子是Docutils常见问题解答 (reStructuredText是与Docutils一起开发的,而Sphinx只是Docutils的扩展)。 Here the FAQ is constructed simply with section headings and the table of contents directive (see the reStructuredText source, link at the bottom of the page). 这里的FAQ简单地用章节标题和目录指令构建(参见页面底部的reStructuredText源代码链接)。

You say in a comment that you already have a table of contents on your page, so want you want is a second table of contents which is local to the FAQ section. 您在评论中说您已经在页面上有一个目录,因此您想要的是第二个目录,这是FAQ部分的本地目录。 This can be done with the :local: option to the contents directive. 这可以通过contents指令的:local:选项来完成。 Try out the following example to see this local table of contents in action: 尝试以下示例以查看此操作中的本地目录:

=======================================
Testing the inclusion of an FAQ section
=======================================

.. contents:: Table of Contents
   :depth: 1

Some uninteresting section
==========================

with some text...

FAQ
===

.. contents::
  :local:
  :backlinks: none
  :depth: 1

Question 1
----------

Lorem ipsum dolor sit amet...

Question 2
----------

Suspendisse tortor tellus...

Question 3
----------

Mauris in magna sed arcu semper auctor vitae eu risus...

Some other uninteresting section
================================

with some text...

See enumerated lists and internal hyperlink targets in the first Google result for "restructuredtext list". 请参阅“重组文本列表”的第一个Google结果中的枚举列表内部超链接目标 You can combine these like so: 您可以将它们组合起来:

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

.. _question 1:
the answer to question 1

For backreferences per your comment, you can use " inline internal targets ", which the quick reference mentions but only the full reference actually describes. 对于每个评论的反向引用,您可以使用“ 内联内部目标 ”,快速参考提及但只有完整参考实际描述。 Unfortunately, it seems to be impossible for the same text to be both a link and a target (even if the syntax technically allowed it, it would be ambiguous), so you would need more text in the list item than just the question. 不幸的是,同一个文本似乎不可能既是一个链接又是一个目标(即使语法在技术上允许它,它也是不明确的),所以你需要列表项中的更多文本而不仅仅是问题。 Your best way might be to have each question link back to the list rather than to a particular list item - eg, 您最好的方法可能是将每个问题链接回列表而不是特定的列表项 - 例如,

.. _List of questions:
...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM