Hyperlink to autonumbered list item

35 views
Skip to first unread message

Josué Andrade Gomes

unread,
Jul 12, 2022, 6:37:51 AM7/12/22
to sphinx...@googlegroups.com

Hi,

I’m trying to create a hyperlink to an autonumbered list item.
The hyperlink works fine but the items are not correctly numbered.

Sample
------

See: :ref:`This <item-1>` and :ref:`That <item-2>`

Items
-----

.. _item-1:

#. Item 1

.. _item-2:

#. Item 2

Results in:

Sample

See: This and That

Items

  1. Item 1

  1. Item 2



Steevie

unread,
Jul 13, 2022, 2:11:36 AM7/13/22
to sphinx...@googlegroups.com
Hi Josué,

On Tue, 12 Jul 2022 07:37:35 -0300, Josué Andrade Gomes wrote:

> Hi,
>
> I’m trying to create a hyperlink to an autonumbered list item. The
> hyperlink works fine but the items are not correctly numbered.
>
> Sample ------
>
> See: :ref:`This <item-1>` and :ref:`That <item-2>`
>
> Items -----
>
> .. _item-1:
>
> #. Item 1
>
> .. _item-2:
>
> #. Item 2

I can confirm the behaviour, which indeed is a bit strange. However, I
made a quick test with the second label indented and it works:

.. _item-1:

#. Item 1

.. _item-2:

#. Item 2

Not sure this solution some unwanted side-effects, though!

Hope this helps,
Stefano


Josué Andrade Gomes

unread,
Jul 13, 2022, 6:27:56 AM7/13/22
to sphinx...@googlegroups.com
Hi Stefano,

> I can confirm the behaviour, which indeed is a bit strange. However, I 
> made a quick test with the second label indented and it works:
> .. _item-1:
> #. Item 1
>    .. _item-2:
> #. Item 2
>  Not sure this solution some unwanted side-effects, though!
> Hope this helps,
Stefano

Great. It worked for me. Thanks.
I didn't notice any side-effects so far.

Josué

Komiya Takeshi

unread,
Jul 18, 2022, 2:27:10 AM7/18/22
to sphinx...@googlegroups.com
Hi,

You can see what happened via `make pseudoxml`. It dumps the
intermediate document structure as XML.

This is a part of generated XML from your snippet.
```
<target refid="item-1">
<enumerated_list enumtype="arabic" ids="item-1" names="item-1"
prefix="" suffix=".">
<list_item>
<paragraph>
Item 1
<target refid="item-2">
<list_item ids="item-2" names="item-2">
<paragraph>
Item 2
```

There are two target nodes. First is placed before enumerated_list,
and another is placed at the tail of the first list_item.
And you can also see the ids attribute on the enumerated_list and the
second list_item.
Docutils automatically copies an ID from the target node to the subsequent node.

This is why your mark-up works.

2022年7月13日(水) 15:11 Steevie <ste...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/talnmd%24jc2%241%40ciao.gmane.io.
Reply all
Reply to author
Forward
0 new messages