mdz-rs
A powerful Rust library for creating and working with MDZ (Markdown Zip) files - self-contained archives that bundle Markdown documents with embedded assets.
๐ Quick Start
Add this to your Cargo.toml:
[]
= "1.1.0"
= { = "1", = ["rt-multi-thread", "macros"] }
๐ Basic Usage
use ;
async
โจ Features
- ๐๏ธ Packaging: Bundle Markdown with images, videos, audio, and other files
- ๐ Smart Downloads: Automatically download network images with UUID filenames
- ๐ Local Files: Intelligently copy local assets with conflict resolution
- ๐ Relative Links: Use relative paths for maximum compatibility
- โช Backward Compatible: Handle legacy MDZ files seamlessly
- ๐ Rich Metadata: Complete manifest with document and asset information
๐๏ธ MDZ Format Structure
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/
๐ง API Reference
Core Functions
pack(markdown_file: &str, output_file: &str) -> Result<()>
Pack a markdown file and its assets into an MDZ archive.
use pack;
async
unpack(input_file: &str, output_dir: Option<&str>) -> Result<()>
Unpack an MDZ archive to extract the markdown file and assets.
use unpack;
Utility Functions
is_url(path: &str) -> bool
Check if a path is a URL or local file path.
use is_url;
assert!;
assert!;
๐ฆ Dependencies
- zip: ZIP archive creation and extraction
- serde + serde_json: JSON serialization for manifest files
- reqwest: HTTP client for downloading network images
- tokio: Async runtime for network operations
- anyhow: Error handling
- url: URL parsing and manipulation
- regex: Markdown link processing
๐ฏ Use Cases
- Document Sharing: Create self-contained documents with embedded images
- Static Site Generation: Package blog posts with assets
- Documentation Systems: Bundle documentation with media files
- Content Management: Archive markdown content with resources
- Educational Materials: Share lessons with embedded media
๐งช Examples
Example 1: Basic Packing
use pack;
async
Example 2: Custom Unpacking
use unpack;
Example 3: Asset Processing
use pack;
use Path;
async
๐ Advanced Usage
Error Handling
use ;
use Result;
async
Asset Detection
The library automatically detects and processes:
- Images: PNG, JPG, JPEG, SVG, GIF, WEBP, etc.
- Videos: MP4, WEBM, AVI, MOV, etc.
- Audio: MP3, WAV, OGG, M4A, etc.
- Files: PDF, DOCX, TXT, and any other file types
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Contributing
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.
๐ Documentation
For complete API documentation, visit docs.rs/mdz-rs.
For the MDZ format specification, see the main project README.