src2md
A CLI tool that bundles text files into a single Markdown document. You can also restore the original files from the Markdown output.
Useful for sharing code with LLMs, creating documentation snapshots, or archiving projects in a readable format.
Note: This project was developed with AI assistance. The codebase is tested and verified by human.
Installation
Or download a binary from Releases.
Downloaded binaries are blocked by Gatekeeper. To allow:
# Remove quarantine attribute after extracting
# Or: Right-click → Open → Open anyway
Quick Start
# Bundle current directory into Markdown
# Only include certain file types
# Bundle a remote git repository
# Generate mdbook format output
# Restore files from a bundle
What It Does
- Walks directories and collects text files
- Wraps each file in a fenced code block with syntax highlighting
- Handles nested code blocks safely (uses extended backtick fences)
- Skips binary files (lists them without content)
- Can restore the original files from the Markdown output
What It Excludes (by default)
- Hidden files and directories (
.git,.env, etc.) - Lock files (
Cargo.lock,package-lock.json,yarn.lock, etc.) - Its own previous output files
Usage Examples
Bundle a Local Project
# Bundle everything in current directory
# Bundle specific directories or files
# Only include Rust and TOML files
# Use a custom ignore file
Clone and Bundle a Git Repository
The --git flag clones a repository to a temporary directory, bundles it, and cleans up automatically:
# Clone and bundle a public repository
# Specify a branch
# Combine with extension filter
The output filename defaults to {repo_name}_content_{timestamp}.md if not specified.
Generate mdbook Format
The --mdbook flag generates output compatible with mdbook:
# Generate mdbook source files
# Then build with mdbook
This creates:
SUMMARY.mdwith chapter structure based on directory layout- One
.mdfile per folder, with each file as a section - Nested folders become nested chapters
Example structure:
book/src/
SUMMARY.md
introduction.md # root files
src.md # files from src/
src/
utils.md # files from src/utils/
Restore Files from Markdown
The --restore flag extracts files from a src2md-generated Markdown back to the filesystem:
# Restore to a specific directory
# Restore to current directory (recreates original structure)
This recreates the original directory structure and file contents. Useful for:
- Recovering code shared in a Markdown document
- Unpacking code snippets from LLM conversations
- Reverting to a previous snapshot
CLI Reference
src2md [OPTIONS] [PATHS]...
Arguments:
[PATHS]... Files or directories to include
Options:
-o, --output <FILE> Output file (default: {project}_{timestamp}.md)
--ignore-file <FILE> Custom ignore file (like .gitignore)
-e, --ext <EXT> Filter by extensions (comma-separated: rs,ts,js)
-v, --verbose Increase verbosity (-v, -vv, -vvv)
--git <URL> Clone and bundle a git repository
-b, --branch <BRANCH> Git branch to checkout (requires --git)
--mdbook <DIR> Generate mdbook format to directory
--restore <FILE> Restore files from a Markdown bundle
--restore-path <DIR> Target directory for restore (default: current dir)
--fail-fast Stop on first error
-h, --help Print help
-V, --version Print version
Library Usage
Add to your Cargo.toml:
[]
= "0.1"
Feature Flags
All features are enabled by default:
| Feature | Description |
|---|---|
restore |
Enables --restore flag and extract_from_markdown API |
git |
Enables --git <URL> to clone and process repositories |
mdbook |
Enables --mdbook <DIR> for mdbook format output |
To use only the core bundling functionality:
= { = "0.1", = false }
Example
use ;
use HashSet;
use PathBuf;
async
See docs.rs for full API documentation.
License
MIT