Search code examples
python-sphinxrestructuredtextread-the-docs

Preformatted (verbatim) hyperlink in Sphinx-reST-RTD


I am building documentation with Sphinx-RTD.

I want to have a link somewhere, and be styled as a verbatim or preformatted text.

For example, say I have this verbatim:

ALTER TABLE

Is there a way to link it somewhere, say a :ref:... or even just a standard hyperlink?


Solution

  • If I am not mistaken the "Replacement Text" directive can help.

    As reStructuredText doesn't support nested inline markup, the only way to create a reference with styled text is to use substitutions with the "replace" directive:

    I recommend you try |Python|_.
    
    .. |Python| replace:: Python, *the* best language around
    .. _Python: http://www.python.org/
    

    So maybe something like this:

    Click |altertable|_ to read details about |altertable|.
    
    ----
    
    Blah blah blah
    
    ----
    
    .. _altertable:
    
    Here are the details about |altertable|: blah blah blah.
    
    .. |altertable| replace:: ``ALTER TABLE``