tree2md-0.7.0 is not a library.
tree2md
Like the tree command, but outputs in Markdown.
Scans directories and prints a Markdown-formatted tree. Optionally embed file contents as syntax-highlighted code blocks.
Table of Contents
- tree2md
Quick Start
# Install
# Show directory tree (no file contents)
# Include file contents as code blocks
Clipboard helpers:
# macOS
|
# Linux
|
# Windows
|
Why tree2md vs. tree
| Capability | tree |
tree2md |
|---|---|---|
| Output Markdown | ✖︎ | ✔ |
| Embed file contents (code blocks) | ✖︎ | ✔ |
| Syntax highlighting hints | ✖︎ | ✔ |
Respect .gitignore |
◯* | ✔ |
| Filter by extension / glob | ◯ | ✔ |
| Drive via stdin (authoritative/merge) | △ | ✔ |
| Flat output for file collections | ✖︎ | ✔ |
| Truncate by bytes / lines | ✖︎ | ✔ |
Security boundary (--restrict-root) |
✖︎ | ✔ |
| Fast, single-binary (Rust) | — | ✔ |
* depending on platform/flags; tree2md respects .gitignore by default.
Features
- Markdown-formatted directory trees
- Optional file contents as fenced code blocks (with language hints)
- Extension filters and glob patterns
- Honors
.gitignoreby default (use--no-gitignoreto disable) - Truncate large files by bytes or lines
- Hidden files/dirs shown by default (use
--exclude-hiddento hide) .git/directory is always excluded for safety and cleanliness- Read paths from stdin (newline or NUL-delimited)
- Flat output for discrete file sets
- Security guardrail with
--restrict-root - Fast & efficient (Rust)
Installation
From crates.io
From source
# Binary at: ./target/release/tree2md
Pre-built binaries
Download from the releases page.
Available for:
- Linux (x86_64)
- macOS (Apple Silicon)
- Windows (x86_64)
Usage
Common recipes
# Quick overview without contents
# Generate README-style docs with contents
# Filter by extensions
# Find with glob patterns (repeatable)
# Exclude hidden files (shown by default)
# Truncate embedded contents (lines or bytes)
# 7) Combine filters + contents + truncation
Git-friendly
# Only Git-tracked TypeScript files
|
# Recently changed files
|
All options (cheat sheet)
Basic
-c, --contents— include file contents as code blocks-t, --truncate <N>— truncate file content to first N bytes--max-lines <N>— limit file content to first N lines-e, --include-ext <EXTS>— comma-separated list (e.g..go,.py)-f, --find <PATTERN>— glob pattern (repeatable), e.g."src/**/*.rs"--exclude-hidden— exclude hidden files/dirs (dotfiles)--no-gitignore— ignore.gitignorefiles and include all files-h, --help/-V, --version
Note: The .git/ directory is always excluded regardless of flags.
Stdin mode
--stdin— read newline-delimited paths from stdin--restrict-root <DIR>— ensure all paths stay within this directory--expand-dirs— expand directories received via stdin--flat— render a flat list (no tree)
Display & paths
--display-path <relative|absolute|input>— default: relative--strip-prefix <PREFIX>— remove prefix from display paths (repeatable)--root-label <LABEL>— custom label for the root (e.g.".","PROJECT_ROOT")
Stdin mode (precise control)
Use stdin when you already have an exact file list (CI pipelines, git ls-files, ripgrep, find).
# Only use files from stdin (no directory scanning)
|
# Expand directories that appear in stdin
|
# Enforce a project boundary (security)
|
Flat mode is great for discrete file collections:
|
Display & path controls
# Show absolute paths
# Strip a common prefix from printed paths
|
Example output
- - - - - -
```rust
fn main() {
}
```
```rust
pub fn add(a: i32, b: i32) -> i32 {
}
```
Supported languages
Language detection for fenced code blocks (non-exhaustive):
- Rust (.rs), Go (.go), Python (.py)
- JavaScript (.js), TypeScript (.ts, .tsx)
- HTML (.html), CSS (.css, .scss, .sass)
- SQL (.sql), Shell (.sh)
- TOML (.toml), YAML (.yaml, .yml)
- JSON (.json), Markdown (.md)
Performance & security
- Designed to be fast and memory-efficient.
- Use
--truncate/--max-linesfor very large files. - Prefer
--respect-gitignoreto avoid noise. - Use
--restrict-rootin scripts/CI to prevent path escapes.
Build from source
Requirements:
- Rust 1.70 or later
- Cargo
# Build release
# Run tests
# Install locally
Contributing
Issues and PRs are welcome. Please include a clear description and, if possible, tests.
License
MIT License