How to add anchor in list element

家住魔仙堡 提交于 2019-12-02 08:49:11

问题


I have a list in my rst file that looks like this:

- Item 1
- Item 2
- Item 3

It renders something like the following (which is exactly what I want):

  • Item 1
  • Item 2
  • Item 3

I would like to create links for each item, so I did

.. _item-1:

- Item 1

.. _item-1:

- Item 2

.. _item-1:

- Item 3

Now my list renders something like this:

  • Item 1

  • Item 2

  • Item 3

This is clearly happening because of the anchors I inserted between the elements. Is there a way to insert referenc-able anchors inline in sphinx/rST?


回答1:


This is pretty close to the desired result, with funky white space.

  .. _item-1:

- Item 1

  .. _item-2:

- Item 2

  .. _item-3:

- Item 3

This yields the following output. Note the id attribute is on the parent <ul> instead of the first <li>, but effectively resolves to the same location on the page.

<ul class="simple" id="item-1">
<li>Item 1</li>
<li id="item-2">Item 2</li>
<li id="item-3">Item 3</li>
</ul>


来源:https://stackoverflow.com/questions/50138672/how-to-add-anchor-in-list-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!