| Crates.io | mdz-rs |
| lib.rs | mdz-rs |
| version | 1.1.0 |
| created_at | 2025-12-13 03:46:56.557533+00 |
| updated_at | 2025-12-13 15:12:47.813748+00 |
| description | A Rust library for creating and working with MDZ (Markdown Zip) files - self-contained archives that bundle Markdown documents with embedded assets |
| homepage | https://github.com/wflixu/mdz |
| repository | https://github.com/wflixu/mdz |
| max_upload_size | |
| id | 1982536 |
| size | 105,489 |
A powerful Rust library for creating and working with MDZ (Markdown Zip) files - self-contained archives that bundle Markdown documents with embedded assets.
Add this to your Cargo.toml:
[dependencies]
mdz-rs = "1.1.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
use mdz_rs::{pack, unpack};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Pack a markdown file with assets
pack("document.md", "document.mdz").await?;
// Unpack MDZ file to extract content and assets
unpack("document.mdz", Some("output/"))?;
Ok(())
}
document.mdz (ZIP archive)
โโโ index.md # Updated markdown with relative asset links
โโโ manifest.json # Metadata and asset mapping
โโโ assets/ # Organized asset files
โโโ images/
โโโ videos/
โโโ audio/
โโโ files/
pack(markdown_file: &str, output_file: &str) -> Result<()>Pack a markdown file and its assets into an MDZ archive.
use mdz_rs::pack;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
pack("report.md", "report.mdz").await?;
println!("Successfully packed report.mdz");
Ok(())
}
unpack(input_file: &str, output_dir: Option<&str>) -> Result<()>Unpack an MDZ archive to extract the markdown file and assets.
use mdz_rs::unpack;
fn main() -> Result<(), Box<dyn std::error::Error>> {
unpack("report.mdz", Some("extracted/"))?;
println!("Successfully unpacked to extracted/");
Ok(())
}
is_url(path: &str) -> boolCheck if a path is a URL or local file path.
use mdz_rs::is_url;
assert!(is_url("https://example.com/image.jpg"));
assert!(!is_url("./local/image.png"));
use mdz_rs::pack;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a markdown file
std::fs::write("example.md", r#"
# My Document


This is a sample document with both local and remote images.
"#)?;
// Pack it into MDZ
pack("example.md", "example.mdz").await?;
println!("Created example.mdz");
Ok(())
}
use mdz_rs::unpack;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Unpack to specific directory
unpack("example.mdz", Some("my_docs/"))?;
// Check extracted files
let markdown = std::fs::read_to_string("my_docs/example.md")?;
println!("Extracted markdown: {}", markdown);
Ok(())
}
use mdz_rs::pack;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let md_file = "portfolio.md";
let output_file = "portfolio.mdz";
// The pack function will:
// 1. Parse the markdown for image links
// 2. Download remote images with UUID names
// 3. Copy local images to assets directory
// 4. Update links to use relative paths
// 5. Create manifest.json with metadata
// 6. Bundle everything into a ZIP file
pack(md_file, output_file).await?;
println!("โ
Created self-contained document!");
println!("๐ Assets are organized in the archive");
println!("๐ Links use relative paths for compatibility");
Ok(())
}
use mdz_rs::{pack, unpack};
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
match pack("missing.md", "output.mdz").await {
Ok(_) => println!("Packing successful"),
Err(e) => eprintln!("Packing failed: {}", e),
}
Ok(())
}
The library automatically detects and processes:
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
For complete API documentation, visit docs.rs/mdz-rs.
For the MDZ format specification, see the main project README.