Crate mdz_rs

Crate mdz_rs 

Source
Expand description

§MDZ - Markdown Zip Library

A Rust library for creating and working with MDZ (Markdown Zip) files. MDZ is a ZIP-based archive format that bundles Markdown documents with their embedded assets (images, videos, audio, and other files) into a single, portable file.

§Features

  • Automatic Asset Processing: Download network images and copy local files
  • Smart Link Resolution: Convert absolute paths to relative paths for maximum compatibility
  • UUID-based Naming: Use UUIDs for downloaded assets to avoid conflicts
  • Backward Compatibility: Handle legacy MDZ files seamlessly
  • Rich Metadata: Complete manifest with document and asset information

§Quick Start

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(())
}

§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/

§Asset Handling

The library automatically processes:

  • Network Images: Downloaded asynchronously with UUID filenames
  • Local Files: Copied with conflict resolution (counter suffixes)
  • Link Updates: Markdown links are updated to use relative paths (./assets/...)
  • Metadata: Complete manifest.json with asset mapping and document info

Structs§

Asset
Represents an embedded asset within an MDZ archive.
Manifest
Manifest structure for MDZ files.

Functions§

is_url
Determines if a given path is a URL or a local file path.
pack
Packs a Markdown file and its assets into an MDZ archive.
unpack
Unpacks an MDZ archive to extract the markdown file and embedded assets.