Skip to content

Instantly share code, notes, and snippets.

@pjbull
Last active March 12, 2017 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjbull/c6d22f34a3a1c20af2d074ef43fa0667 to your computer and use it in GitHub Desktop.
Save pjbull/c6d22f34a3a1c20af2d074ef43fa0667 to your computer and use it in GitHub Desktop.
Prints the output of the tree command as a markdown table for documentation
import subprocess
path = ROOT_DIR
result = (subprocess.check_output(['tree', '--dirsfirst', path])
.decode("utf-8", "strict"))
file_list = result.split('\n')
root = file_list[0]
file_list = file_list[1:-3]
header_fmt = "<tr><th style='white-space:nowrap;'><code>{}</code></th><th></th></tr>"
file_fmt = """<tr>
<td nowrap><code>{}</code></td>
<td>description</td>
</tr>
"""* len(file_list)
formatted = """
<table>
<thead>
{}
</thead>
<tbody>
{}
</tbody>
</table>
""".format(
header_fmt.format(root),
file_fmt.format(*file_list)
)
print(formatted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment