Anchor at arbitrary position with sphinx / reStructuredText?

Is it possible to add an anchor (the target of the link that I can refer to :ref:

) at an arbitrary position in the text? I have a situation like this:

Some text

.. class:: mylist

**Term 1**
  Definition

*Term 2*
  Definition

:customrole:`Term 3` extra
  Definition

      

And I would like to add a link, say Term 2

. I can't just add .. _target:

in front of the block because that splits the list in half and the second part doesn't get the class mylist

(is this intentional or could it be a bug?). I could write this:

*Term 2*
  .. _target:

  Definition

      

but then the target is the paragraph of the definition, not the element itself Term 2

.

Applying the inline role to is Term 2

also tricky, because then there is the problem of nested formatting (I used different styles for each one to show that there could be many situations that I would need). Maybe if I could apply the inline role to some empty text ...

Any suggestion?

+2


source to share


1 answer


I just answered a similar question here, hopefully this solves your problem:

Python Sphinx kernel on arbitrary line



Finally, you can use the role ref

: http://sphinx-doc.org/markup/inline.html#role-ref

In particular, read the second bullet point, which looks at what happens if the link doesn't fit before the heading.

0


source







All Articles