How to include an internal link in a code block?

In my Sphinx.rst document, I have a code block containing the tree structure of my product structure using the UNIX command tree:

  |── parent
  |   |── child
  |       |── grandchild

This is in a block of code, so Sphinx preserves spaces.

I want readers to be able to click on each node to follow the internal hyperlink

+6
source share
2 answers

You can use the directive parsed-literal:

.. parsed-literal:: 

   |── :ref:`parent`
   |   |── :ref:`child`
   |       |── :ref:`grandchild`

This works, but there are warning messages that say "WARNING: Starting substitution string substring_reference without ending string".

. :

.. parsed-literal:: 

   \|── :ref:`parent`
   |   \|── :ref:`child`
   |       \|── :ref:`grandchild`
+3

.. code-block:: , ​​ .

CSS my-special-class CSS, HTML <pre> <code>. | \|, reST | .

Rest:

.. rst-class:: my-special-class

\|── :ref:`parent`
\|   \|── :ref:`child`
\|       \|── :ref:`grandchild`

CSS

.my-special-class {
    font-family: monospace;
    white-space: pre;
}
+1

All Articles