Custom inline role for hyperlinks in Docutils/Sphinx

42 Views Asked by At

I would like to define a special class of hyperlinks.

For regular text span, this would be done by defining and using a custom role like this:

.. role:: myrole

This is :myrole:`whatever`.

which then appears as <span class="myrole">whatever</span> in HTML and as \DUrole{myrole}{whatever} in LaTeX (as documented).

Is there a way to do the same for hyperlinks, so that I get \DUrole{myrole}{\sphinxhref{target}{text}} in LaTeX?

The issue is, hyperlinks don't seem to have a named role (so that one could define inherited role .. role:: myhyper(hyperlink)) and can only be created with backticks:

`text <target>__`

which can't be nested in another role's parameter because of the backticks.

(There is a way to create those with MyST parser and attrs_inline extension as [text](target){.myhyper}, but it only works with the HTML writer and does not get exported into LaTeX.)

0

There are 0 best solutions below