python-sphinxrestructuredtext

Create a reference inside a reStructuredText CSV table


I have a CSV table like this

.. csv-table::
   :header: Name, BrowseName, DataType, Description
   :widths: 16,16,16,52

   "Enabled", "Enabled", "Boolean", "Alarm can..."

and I would like to create a reference to a row in the HTML output. I tried to put .. _reference: to every place in the table, but either I have a compile error or an empty cell. I tried also to use a reST substitution definition, but without success.

Do you know if there is a way to add such a reference in that kind of table or references work only within grid tables?


Solution

  • You can insert arbitrary reST in your CSV, similar to this answer. The alignment is tricky, so I recommend indenting everything uniformly by 4 spaces. The label is inserted in the second row and the :ref: directive must be given both a title and the label, per Sphinx's documentation on the :ref: role.

    :ref:`link to hello <mylabel>`
    
    .. csv-table:: Test csv-table with multi-paragraph
        :header: "a", "b", "c"
    
        Cat,"Chunk that is updated periodically via copy-and-paste.
    
        Line #2, #3, etc", "Kitten"
        Dog,".. _mylabel:
    
        Hello", "Puppy"
        Walrus,"#.  List Item 1
        #.  List Item 2
        #.  List Item 3", "Pup"