tree2md-0.4.1 is not a library.
tree2md
A command-line tool that scans directories and outputs their structure in Markdown format. Can optionally include file contents as code blocks with syntax highlighting.
Features
- Generate Markdown-formatted directory trees
- Include file contents as syntax-highlighted code blocks
- Filter files by extension
- Find files using wildcard patterns (glob)
- Respect
.gitignorepatterns - Truncate large files by bytes or lines
- Support for hidden files and directories
- Read file paths from stdin for precise control
- Flat output format for discrete file collections
- Security boundary enforcement with
--restrict-root - Fast and efficient, written in Rust
Installation
From crates.io
From source
# Binary will be at ./target/release/tree2md
Pre-built binaries
Download pre-built binaries from the releases page.
Available for:
- Linux (x86_64)
- macOS (Apple Silicon)
- Windows (x86_64)
Usage
Common Use Cases
# Copy project structure to clipboard for documentation (macOS)
|
# Copy project structure to clipboard (Linux)
|
# Copy project structure to clipboard (Windows)
|
# Generate README documentation
# Quick overview without file contents
|
All Options
# Basic usage - output tree structure of current directory
# Scan specific directory
# Include file contents as code blocks
# Filter by extensions
# Find files matching wildcard patterns
# Include hidden files
# Respect .gitignore
# Truncate file contents
# Combine options
Stdin Mode
Read file paths from stdin for precise control over which files to include:
# Document only Git-tracked TypeScript files
|
# Document recently changed files
|
# Use with find for null-delimited paths (handles spaces/special chars)
|
# Expand directories found in stdin
|
# Keep input order (useful for prioritized documentation)
|
# Restrict paths to project directory (security)
|
# Merge stdin with directory scan
|
# Use flat format for discrete file collections
|
# Use relative paths (default in v0.4.0+)
|
# Show display root for reproducibility
|
# Strip common prefix from paths
|
Options
Basic Options
-c, --contents- Include file contents as code blocks-t, --truncate <N>- Truncate file content to the first N bytes--max-lines <N>- Limit file content to the first N lines-e, --include-ext <EXTS>- Comma-separated list of extensions to include (e.g., .go,.py)-f, --find <PATTERNS>- Find files matching wildcard patterns (can be used multiple times)-a, --all- Include hidden files and directories--respect-gitignore- Respect .gitignore files-h, --help- Print help information-V, --version- Print version information
Stdin Mode Options
--stdin- Read file paths from stdin (newline-delimited)--stdin0- Read file paths from stdin (null-delimited, for paths with spaces)--stdin-mode <authoritative|merge>- How to handle stdin input (default: authoritative)authoritative: Use only files from stdinmerge: Combine stdin files with directory scan
--keep-order- Preserve the input order from stdin (default: sort alphabetically)--base <DIR>- Base directory for resolving relative paths from stdin (default: current directory)--restrict-root <DIR>- Ensure all paths are within this directory (security feature)--expand-dirs- Expand directories found in stdin to their contents--flat- Use flat output format instead of tree structure
Display Path Options
--display-path <relative|absolute|input>- How to display paths (default: relative)relative: Show paths relative to display rootabsolute: Show absolute pathsinput: Show paths as provided in stdin
--display-root <DIR>- Custom root for relative path display (default: auto-detect via LCA)--strip-prefix <PREFIX>- Remove prefix from display paths (can be used multiple times)--show-root- Show the display root at the beginning of output--no-root- Don't show root node in tree output (default for stdin mode)--root-label <LABEL>- Custom label for root node (e.g., ".", "PROJECT_ROOT")--pure-json- Keep JSON output pure without comment lines
Example Output
- - - - - -
```rust
// src/main.rs
fn main() {
}
```
```rust
// src/lib.rs
pub fn add(a: i32, b: i32) -> i32 {
}
```
Supported Languages
The tool automatically detects and applies syntax highlighting for:
- Rust (.rs)
- Go (.go)
- Python (.py)
- JavaScript (.js)
- TypeScript (.ts, .tsx)
- HTML (.html)
- CSS (.css, .scss, .sass)
- SQL (.sql)
- Shell scripts (.sh)
- TOML (.toml)
- YAML (.yaml, .yml)
- JSON (.json)
- Markdown (.md)
Building from Source
Requirements:
- Rust 1.70 or later
- Cargo
# Clone the repository
# Build release version
# Run tests
# Install locally
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.