tree2md 0.8.0

Like the tree command, but outputs in Markdown. Optionally embed file contents as code blocks.
tree2md-0.8.0 is not a library.

tree2md

Crates.io License: MIT

Generate GitHub-ready project structure documentation with clickable links.

A safe, fast tool that creates beautiful Markdown tree visualizations of your project structure โ€” perfect for README files, documentation, and GitHub repositories. No file contents are ever exposed, keeping your code secure.


๐ŸŽฏ Key Features

  • ๐Ÿ“ Collapsible Trees โ€” Navigate large projects easily with <details>
  • ๐Ÿ”— GitHub Integration โ€” Automatic link rewriting for GitHub URLs
  • ๐Ÿ”’ Safe by Default โ€” Excludes secrets, .env, keys, node_modules/, etc.
  • ๐ŸŽจ Smart Formatting โ€” Deterministic output (dirs first, alphabetical order)
  • ๐Ÿ“Š Statistics โ€” File counts, top extensions, LOC counts
  • ๐Ÿ“ README Injection โ€” Auto-update README.md between tags (idempotent)

๐Ÿ“ฅ Installation

From crates.io

cargo install tree2md

From source

git clone https://github.com/zawakin/tree2md
cd tree2md
cargo install --path .

Pre-built binaries

Download from GitHub Releases


๐Ÿš€ Quick Start

# Generate a tree (pretty tty-style)
tree2md

# Generate a Markdown tree (safe mode by default)
tree2md . > STRUCTURE.md

# Add GitHub links
tree2md . --github https://github.com/you/repo/tree/main

# Inject into README.md automatically
tree2md . --github https://github.com/you/repo/tree/main --inject README.md

# Limit depth & filter
tree2md . -L 3 -I "*.rs" -I "*.md"

๐Ÿ“‹ Example Output

- src/
  - [cli.rs]src/cli.rs (452 lines)
  - [main.rs]src/main.rs (262 lines)
- tests/
  - [emoji_test.rs]tests/emoji_test.rs (175 lines)
  - [filtering_test.rs]tests/filtering_test.rs (295 lines)
  - [safety_test.rs]tests/safety_test.rs (357 lines)
- [Cargo.toml]Cargo.toml (36 lines)
- [LICENSE]LICENSE (21 lines)
- [README.md]README.md (310 lines)

**Totals**: ๐Ÿ“‚ 2 dirs โ€ข ๐Ÿ“„ 8 files โ€ข ๐Ÿงพ ~1.7K LOC

**By type**:
- Test: 3 (38%) ######---------
- Rust: 2 (25%) ####-----------
- Markdown: 1 (13%) ##-------------
- TOML: 1 (13%) ##-------------
- License: 1 (13%) ##-------------

๐Ÿ› ๏ธ CLI Options

Filtering

  • -L, --level <N> โ€” Limit traversal depth
  • -I, --include <GLOB> โ€” Include patterns (repeatable)
  • -X, --exclude <GLOB> โ€” Exclude patterns (repeatable)
  • --use-gitignore {auto|never|always} โ€” Respect .gitignore

Links & Output

  • --links {on|off} โ€” Toggle Markdown links
  • --github <URL> โ€” Rewrite links to GitHub
  • --fold {auto|on|off} โ€” Collapsible folders
  • --no-stats โ€” Hide stats footer

Safety

  • --safe (default) โ€” Excludes sensitive files
  • --unsafe โ€” Disable all safety filters
  • --restrict-root <DIR> โ€” Prevent traversal outside root

README Integration

  • --inject <FILE> โ€” Update README.md between tags
  • --tag-start <STR> โ€” Custom start tag (default: <\!-- tree2md:start -->)
  • --tag-end <STR> โ€” Custom end tag (default: <\!-- tree2md:end -->)
  • --dry-run โ€” Preview without writing

Metadata

  • --stamp {version|date|commit|none} โ€” Add generation metadata
  • --stamp-date-format <FMT> โ€” Date format

๐Ÿ”’ Safety Defaults

Excluded by default:

  • .env, .ssh/**, *.pem, *.key
  • node_modules/, target/, dist/, build/
  • .git/**, .DS_Store, Thumbs.db

Use -I to selectively include, or --unsafe to disable filters.


๐Ÿ“ Common Use Cases

README injection

tree2md . --github https://github.com/you/repo/tree/main --inject README.md

Docs / Architecture

tree2md src --fold on > docs/ARCHITECTURE.md

Code reviews

tree2md . -L 3 -I "*.rs" -I "*.toml" --no-stats

CI/CD auto-update

tree2md . --github $GITHUB_URL --inject README.md --stamp version
git add README.md
git commit -m "Update structure"

โšก Performance

  • Fast โ€” Parallel traversal with efficient filtering
  • Memory safe โ€” Streams output, no huge buffers
  • Deterministic โ€” Always the same result for same input
  • Git-aware โ€” Respects .gitignore

๐Ÿ—๏ธ Build from Source

git clone https://github.com/zawakin/tree2md
cd tree2md
cargo build --release
cargo test

๐Ÿค Contributing

PRs welcome! See CONTRIBUTING.md.

For development:

cargo fmt
cargo clippy -- -D warnings

๐Ÿ“‚ Project Structure

Markdown-Style

tree2md -L 2 . --output md --inject README.md --tag-start '<tag-start>'
<!-- tree2md-md:start -->
- .claude/
- .github/
- scripts/
  - [update-readme-embeds.sh]scripts/update-readme-embeds.sh (28 lines)
- src/
  - [cli.rs]src/cli.rs (452 lines)
  - [main.rs]src/main.rs (262 lines)
- tests/
  - [emoji_test.rs]tests/emoji_test.rs (175 lines)
  - [exclude_pattern_test.rs]tests/exclude_pattern_test.rs (125 lines)
  - [filtering_test.rs]tests/filtering_test.rs (295 lines)
  - [fixtures.rs]tests/fixtures.rs (272 lines)
  - [html_output_test.rs]tests/html_output_test.rs (448 lines)
  - [include_directory_test.rs]tests/include_directory_test.rs (112 lines)
  - [include_pattern_test.rs]tests/include_pattern_test.rs (85 lines)
  - [links_test.rs]tests/links_test.rs (377 lines)
  - [output_format_test.rs]tests/output_format_test.rs (177 lines)
  - [preset_test.rs]tests/preset_test.rs (203 lines)
  - [safety_test.rs]tests/safety_test.rs (357 lines)
  - [spec_compliance_test.rs]tests/spec_compliance_test.rs (422 lines)
  - [stats_test.rs]tests/stats_test.rs (279 lines)
- [.gitignore].gitignore (30 lines)
- [CHANGELOG.md]CHANGELOG.md (252 lines)
- [CLAUDE.md]CLAUDE.md (9 lines)
- [Cargo.lock]Cargo.lock
- [Cargo.toml]Cargo.toml (36 lines)
- [LICENSE]LICENSE (21 lines)
- [README.md]README.md (310 lines)

**Totals**: ๐Ÿ“‚ 6 dirs โ€ข ๐Ÿ“„ 23 files โ€ข ๐Ÿงพ ~4.7K LOC

**By type**:
- Test: 12 (52%) ########-------
- Rust: 3 (13%) ##-------------
- Markdown: 3 (13%) ##-------------
- License: 1 (4%) #--------------
- TOML: 1 (4%) #--------------
- Shell: 1 (4%) #--------------
- Ignore: 1 (4%) #--------------
- Lock: 1 (4%) #--------------

<!-- tree2md-md:end -->

Tree-Style

tree2md -L 2 . --output md --inject README.md --tag-start '<tag-start>'
<!-- tree2md-tree:start -->
|-- .claude/
|-- .github/
|-- scripts/
|   `-- update-readme-embeds.sh        [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ]      28 (S)
|-- src/
|   |-- cli.rs                         [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ]     452 (L) โ˜…
|   `-- main.rs                        [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆยทยทยทยท]     262 (M)
|-- tests/
|   |-- emoji_test.rs                  [โ–ˆโ–ˆโ–ˆโ–ˆยทยทยทยทยทยท]     175 (M)
|   |-- exclude_pattern_test.rs        [โ–ˆโ–ˆโ–ˆยทยทยทยทยทยทยท]     125 (M)
|   |-- filtering_test.rs              [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆยทยทยท]     295 (M)
|   |-- fixtures.rs                    [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆยทยทยท]     272 (M)
|   |-- html_output_test.rs            [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ]     448 (L) โ˜…
|   |-- include_directory_test.rs      [โ–ˆโ–ˆโ–ˆยทยทยทยทยทยทยท]     112 (S)
|   |-- include_pattern_test.rs        [โ–ˆโ–ˆยทยทยทยทยทยทยทยท]      85 (S)
|   |-- links_test.rs                  [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆยท]     377 (L)
|   |-- output_format_test.rs          [โ–ˆโ–ˆโ–ˆโ–ˆยทยทยทยทยทยท]     177 (M)
|   |-- preset_test.rs                 [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆยทยทยทยทยท]     203 (M)
|   |-- safety_test.rs                 [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆยทยท]     357 (L)
|   |-- spec_compliance_test.rs        [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ]     422 (L)
|   `-- stats_test.rs                  [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆยทยทยท]     279 (M)
|-- .gitignore                         [โ–ˆยทยทยทยทยทยทยทยทยท]      30 (S)
|-- CHANGELOG.md                       [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆยท]     252 (M)
|-- CLAUDE.md                          [ยทยทยทยทยทยทยทยทยทยท]       9 (XS)
|-- Cargo.lock
|-- Cargo.toml                         [โ–ˆโ–ˆยทยทยทยทยทยทยทยท]      36 (S)
|-- LICENSE                            [โ–ˆยทยทยทยทยทยทยทยทยท]      21 (S)
`-- README.md                          [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ]     310 (L)

**Totals**: ๐Ÿ“‚ 6 dirs โ€ข ๐Ÿ“„ 23 files โ€ข ๐Ÿงพ ~4.7K LOC

**By type**:
- Test: 12 (52%) ########-------
- Rust: 3 (13%) ##-------------
- Markdown: 3 (13%) ##-------------
- Lock: 1 (4%) #--------------
- Shell: 1 (4%) #--------------
- TOML: 1 (4%) #--------------
- Ignore: 1 (4%) #--------------
- License: 1 (4%) #--------------

<!-- tree2md-tree:end -->

๐Ÿ“„ License

MIT License โ€” see LICENSE.


๐Ÿ™ Acknowledgments

Inspired by the classic tree command, designed for Markdown & GitHub integration.

Made with โค๏ธ for the open source community.