How to Correctly Display Pipe/Vertical Bar Character in Python Docstrings Using Sphinx

Question:

I’d like to put in a Python docstring something like:

output_dir
│   categories.yaml
│
└───images
│       filename1.png
│       filename1.png
│       ...
│
└───masks
        filename1.png
        filename2.png
        ...

But this is visualized by Sphinx as:

output_dir │ categories.yaml │ └───images │ filename1.png │ filename1.png │ … │ └───masks filename1.png filename2.png …

Any idea how to do it?

Thanks!

Answers:

Put the content in a literal block in the docstring (note the indentation and the double colon):

"""
Here is the directory structure::

   output_dir
   │   categories.yaml
   │
   └───images
   │       filename1.png
   │       filename1.png
   │       ...
   │
   └───masks
           filename1.png
           filename2.png
           ...

"""

To do the same without showing the ":" is enough to have a whitespace before "::", like:

"""
Here is the directory structure::

        output_dir
        │   categories.yaml
        │
        └───images
        │       filename1.png
        │       filename1.png
        │       ...
        │
        └───masks
                filename1.png
                filename2.png
                ...
    
    or ::
    
        output_dir
        │   categories.yaml
        │
        └───test
        │   └───images
        │   │       filename1.png
        │   │       filename1.png
        │   │       ...
        │   │
        │   └───masks
        │   │       filename1.png
        │   │       filename2.png
        │   │       ...
        │
        └───train
        └───val
"""

This will show ":" after "structure" but not after "or".

Answered By: mzjn
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.