1

I'm trying to make a substitution on the file loaded by the table-csv directive on Sphinx. My idea was to do something like:

.. csv-table:: My CSV Table
:header: "Column 1", "Column 2"
:file: some/path/|branch|/to/file_|version|.csv

It seems to replace neither branch nor version.

I tried to add white spaces around the variables I want to substitute as on the answer for this question

I also tried (without success) to create a variable with the full path outside, on conf.py as follows.

rst_prolog = f"""    
.. |my_csv_file| replace:: ../path/{git_branch}/to/file_{version}.csv
"""

To then import it as:

.. csv-table:: My CSV Table
    :header: "Column 1", "Column 2"
    :file: | my_csv_file |

Is there any way (without using custom directives if possible) to achieve this?

Thanks beforehand!

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Salva Corts
  • 862
  • 1
  • 7
  • 12
  • 1
    [Substitutions](https://docutils.sourceforge.io/docs/ref/rst/directives.html#directives-for-substitution-definitions) can be used only to replace text and inline elements, not within directives or their options. – Steve Piercy Jun 10 '20 at 22:10

1 Answers1

1

CSV tables treat data as-is. They are even not picked up by gettext to be translated.

I recommend you to use list-table or grid (painted) table. It both works with |subtitution| and are localizable.

.. |project-name| replace:: SuperSecretProject

.. list-table::
   :header-rows: 1
   :widths: auto

   * - Parameter
     - Description

   * - ``UserId``
     - ID of allowed user that can enter |project-name|.
Matt Warrick
  • 1,385
  • 1
  • 13
  • 22