mdpack 0.1.2

Pack codebases into Markdown bundles and expand them back into files.
Documentation

mdpack

Pack codebases into code2prompt-style Markdown bundles and expand them back into files. Inspired by code2prompt. Ships as both a CLI and a reusable Rust library.

Features

  • Bundle a directory into a single Markdown file.
  • Restore a bundle back into a directory.
  • Safe path handling (no absolute paths or parent traversal).
  • Works as a CLI and as a library API.

Install (CLI)

From crates.io

cargo add mdpack

From this repository:

cargo install --git https://github.com/AlextheYounga/mdpack.git

CLI usage

Pack a directory:

mdpack pack ./my-project -o bundle.md

If -o is omitted, the bundle is written to bundle.md in the current directory.

Unpack a bundle:

mdpack unpack bundle.md -o ./my-project

If -o is omitted, files are written to the current directory.

Options:

  • --include-hidden to include dotfiles during packing.
  • --ignored to include files matched by gitignore rules during packing.
  • --force to overwrite existing files during unpacking.

Library usage

Add as a dependency:

[dependencies]
mdpack = { git = "https://github.com/AlextheYounga/mdpack.git" }

Pack to a string or file:

use mdpack::{pack_to_path, pack_to_string, PackOptions};
use std::path::Path;

let options = PackOptions {
    include_hidden: false,
    include_ignored: false,
};
let bundle = pack_to_string(Path::new("./my-project"), options)?;
pack_to_path(Path::new("./my-project"), Path::new("bundle.md"), options)?;

Unpack from a string or file:

use mdpack::{unpack_from_path, unpack_from_str, UnpackOptions};
use std::path::Path;

let options = UnpackOptions { force: false };
let output = unpack_from_str("`foo.txt`:\n\n```\ncontent\n```\n", None, options)?;
unpack_from_path(Path::new("bundle.md"), Some(Path::new("./out")), options)?;

Format

Bundles follow the code2prompt layout, minus the Project Path: line:

  • Source Tree: section with an ASCII tree
  • Per-file blocks in the form:
`path/to/file`:

```lang
<file contents>
```

Tests

cargo test