0

I am trying to add a javascript to tree -h output an HTML file that can collapse all the child elements and would only display the parent elements. I find it difficult to do it with JavaScript because there are not differentiating parameters in the created HTML file via tree -h. Does anybody know if we can edit the HTML file in a way that the parent directory becomes collapsible by default and can be expanded to view the contents of it?

The output of file.html:

<html>
<body>
<h1>Directory Tree</h1><p>
<a href=".">.</a><br>
├── <a href="./1">1</a><br>
├── <a href="./b6a8F5G.gif">b6a8F5G.gif</a><br> 
├── <a href="./error-page/">error-page</a><br>
│   ├── <a href="./error-page/css/">css</a><br>
│   │   └── <a href="./error-page/css/style.css">style.css</a><br>
│   ├── <a href="./error-page/index.html">index.html</a><br>
│   ├── <a href="./error-page/wrong-password.html">wrong-password.html</a><br>
│   └── <a href="./error-page/wrongsr.html">wrongsr.html</a><br>
├── <a href="./sr_fix.py">sr_fix.py</a><br>
├── <a href="./test_nova.py">test_nova.py</a><br>
├── <a href="./test-req.py">test-req.py</a><br>
└── <a href="./testspace.py">testspace.py</a><br>
<br><br>
</p>
<p>
<br><br>
</p>
<hr>

</body>
</html>

1 Answer 1

3

You could use the JSON output of tree(1) instead (tree -J) and then render the resulting json using one of the many available JS-based renderers on the web, e. g.:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .