Format text in a link in reStructuredText

This construct: Here you have |optparse.OptionParser|_. .. |optparse.OptionParser| replace:: “optparse.OptionParser“ documentation .. _optparse.OptionParser: produces this HTML (some linebreaks added): <p>Here you have <a class=”reference external” href=””> <tt class=”docutils literal”><span class=”pre”>optparse.OptionParser</span></tt> documentation</a>. </p> I realize that this is not exactly what you asked for, but maybe it’s close enough. See also

Adding a cross-reference to a subheading or anchor in another page

The expression “reST/Sphinx” makes the scope of the question unclear. Is it about reStructuredText in general and Sphinx, or only about reStructuredText as used in Sphinx (and not reStructuredText in general)? I’m going to cover both since people using RST are likely to run into both cases at some point: Sphinx Besides the domain-specific directives … Read more