Reputation: 892
I'm trying to make a substitution on the file loaded by the csv-table
directive in Sphinx.
My idea was to do something like this:
.. 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 in the answer for this question.
I also tried (without success) to create a variable with the full path outside, in 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?
Upvotes: 1
Views: 1308
Reputation: 872
Substitution in the table content works also with a csv-table:
.. |column-2| replace:: Description
.. |project-name| replace:: SuperSecretProject
.. csv-table:: My CSV Table
:header: Parameter, |column-2|
``N`` , number of parrots
``UserID``, ID of allowed user that can enter |project-name|
You may also save
``N`` , number of parrots
``UserID``, ID of allowed user that can enter |project-name|
to a file mytable.csv
, say and load it in the main document
.. |column-2| replace:: Description
.. |project-name| replace:: SuperSecretProject
.. csv-table:: My CSV Table
:header: Parameter, |column-2|
:file: mytable.csv
The |project-name|
will be replaced with the substitution definition in the including document.
Upvotes: 0
Reputation: 1488
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|.
Upvotes: 1