How to create ad hoc HTML anchors?

23 views
Skip to first unread message

Pete

unread,
Dec 7, 2020, 7:07:03 PM12/7/20
to sphinx-users
What I want to do is write the .rst code for this HTML output:

instead of:        <strong>energy</strong>
it has to be:      <strong id="energy">energy</strong>

How is this done?  The .rst code I'm using now is:   **energy**

This will be used hundreds of times (using a software program to convert source into .rst files) in a multipage document (~150 .rst files) so a simple reference label approach, such as `.. _energy:`  would likely be created on different pages, generating multiply-defined errors.

BTW, the word "energy" is just an example of the type of words that word be anchored.

related topics:
* https://groups.google.com/g/sphinx-dev/c/bNW2Tc4hhOA

Luc Saffre

unread,
Dec 8, 2020, 4:56:00 AM12/8/20
to sphinx...@googlegroups.com, Pete
Looks as if you want the glossary directive (and the term role):
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-glossary

Luc
--
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/57d82d37-a9e3-416d-9c3e-b89e14784b03n%40googlegroups.com.

Martin Bless

unread,
Dec 8, 2020, 5:37:57 AM12/8/20
to sphinx...@googlegroups.com

You can make it a inline hyperlink target like so:


I love the big _`energy` of it all.
And I often use energy_ for fun.

This result is what you get:

<p>I love the big <span class="target" id="energy">energy</span> of it all.
And I often use <a class="reference internal" href="#energy">energy</a> for fun.</p>


Cheers,

Martin.


Am 08.12.20 um 10:55 schrieb Luc Saffre:
Reply all
Reply to author
Forward
0 new messages