15

I would like to present the output of a tree command in a Restructured Text document. I am using this code:

.. code-block:: bash

   project
   ├── demo.py
   ├── LICENCE.txt
   ├── processes          
   │   ├── area.py
   │   └── bboxinout.py
   ├── pywps.cfg          
   ├── requirements.txt
   ├── server.py          
   ├── setup.py
   ├── static
   ├── templates
   └── tests

Which is producing the following output:

enter image description here

I then tried to replace the tree characters with unicode definitions, such as:

.. |hbar| unicode:: 01C0 ..

But the |hbar| sequence is printed verbatim when used inside a code block.

Is there any other way to force these characters to be printed correctly?

Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86
  • 1
    What source encoding do you use. I pasted the output from tree into a utf8 document and generated output containing the correct box drawing characters. – P.G. Jun 22 '16 at 09:02

2 Answers2

16

In ReST, I use literal blocks to represent tree structures:

::

    project
    ├── demo.py
    ├── LICENCE.txt
    ├── processes          
    │   ├── area.py
    │   └── bboxinout.py
    ├── pywps.cfg          
    ├── requirements.txt
    ├── server.py          
    ├── setup.py
    ├── static
    ├── templates
    └── tests

I hope this helps!

Eric D.
  • 305
  • 1
  • 11
  • 1
    Unfortunately, this code produces the exact same result as seen in the question. – Luís de Sousa Aug 08 '16 at 07:13
  • Interesting, sorry my previous answer didn't work for you. Although it's a two step process, are you able to generate the folder structure using something like tree (tree.com) in your terminal/shell and then copy it into your text editor? I was able to get that to work yesterday using a utf8 formatted document. – Eric D. Aug 08 '16 at 10:58
  • It works. pandoc can recognize this structure and convert it to markdown format. – Chenlu Jun 28 '18 at 13:53
5

A bit too late to answer your question now, but for anyone coming across this question, I managed to display a tree by using line blocks, i.e. adding "| " at the start of every line, as such:

| project
| ├── demo.py
| ├── LICENCE.txt
| ├── processes          
| │   ├── area.py
| │   └── bboxinout.py
| ├── pywps.cfg          
| ├── requirements.txt
| ├── server.py          
| ├── setup.py
| ├── static
| ├── templates
| └── tests

And when you make your html, this should give you something like this:

enter image description here

It's not perfect and it does not wrap the tree in a block, but does show the tree.

Hope this helps.

sglvladi
  • 86
  • 1
  • 3