Skip to main content

Bundle code blocks into downloadable ZIP or raw files — for MkDocs/Material and Zensical.

Project description

mkdocs-zip-bundle-plugin

Turn code blocks into downloadable files — for MkDocs/Material and Zensical. Tag any code block with a bundle ID and filename and a download button is injected automatically. Works with single files (direct download) or multiple files (ZIP archive).

Built to pair with mkdocs-placeholder-plugin: if your docs use interactive placeholders like @PORT@, the downloaded file will contain the user's actual values, not the defaults. (MkDocs/Material — see Using with Zensical for the Zensical caveat.)

Live demo → mkdocs-zip-bundle-plugin.daemonless.io

Features

  • Single file downloads — one code block gets a direct raw file download, no ZIP needed
  • Multi-file ZIP bundles — group multiple code blocks into one ZIP with a single button
  • Placeholder-aware — captures the live browser state, so user-edited values are included in the download
  • Nested paths — use configs/app.yaml as a filename to create subdirectories inside the ZIP
  • Custom button labels — override auto-generated text per bundle
  • Self-contained — ships with JSZip and default styling, no extra dependencies

Installation

pip install mkdocs-zip-bundle-plugin

Requires Python 3.8+ and MkDocs 1.4+. Download buttons require a modern browser (Chrome, Firefox, Safari, Edge).

Configuration

plugins:
  - search
  - zip-bundle:
      include_jszip: true   # set to false if you already load JSZip elsewhere
      zip_label_suffix: "(.zip)"  # appended to multi-file bundle button labels

Also enable the attr_list extension so MkDocs can read attributes on code blocks:

markdown_extensions:
  - attr_list
  - pymdownx.superfences  # recommended for reliable attribute support

Usage

Add data-zip-bundle and data-zip-filename attributes to any fenced code block:

Single file

```yaml { data-zip-bundle="my-app" data-zip-filename="compose.yaml" }
services:
  app:
    image: my-image:latest
```

The plugin injects a Download compose.yaml button directly after the code block.

Multiple files (ZIP)

```yaml { data-zip-bundle="my-app" data-zip-filename="compose.yaml" }
services:
  app:
    image: my-image:latest
```

```bash { data-zip-bundle="my-app" data-zip-filename="setup.sh" }
mkdir -p /data/app
```

Both blocks share the same bundle ID. The plugin injects a single Download My App (.zip) button after the last block.

Custom button label

```yaml { data-zip-bundle="my-app" data-zip-filename="compose.yaml" data-zip-label="Download config" }
...
```

Force ZIP for a single file

```yaml { data-zip-bundle="my-app" data-zip-filename="compose.yaml" data-zip-force="true" }
...
```

Nested directories

```yaml { data-zip-bundle="my-app" data-zip-filename="config/app.yaml" }
...
```

```bash { data-zip-bundle="my-app" data-zip-filename="scripts/setup.sh" }
...
```

The ZIP will contain config/app.yaml and scripts/setup.sh preserving the directory structure.

How it works with placeholders

If you use mkdocs-placeholder-plugin, your docs can have editable values like @PORT@ or @DATA_PATH@ that users customize in the browser.

When the user clicks a download button from this plugin, the downloaded file contains whatever is currently in the code block — including any values the user has already changed. This makes it possible to offer personalized, copy-paste-ready config files directly from your documentation.

License

MIT — see LICENSE for details. Bundles JSZip (MIT).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs_zip_bundle_plugin-0.2.0.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_zip_bundle_plugin-0.2.0-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_zip_bundle_plugin-0.2.0.tar.gz.

File metadata

  • Download URL: mkdocs_zip_bundle_plugin-0.2.0.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for mkdocs_zip_bundle_plugin-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ce68d26bfead9f4ff16f76857142541a0d111e72798c784b1411495567f82c52
MD5 652dc61dca827469c0ccebb225577281
BLAKE2b-256 a9661e8c85191f56a29f0273b41513e2c53910a09c2bb787dd328a6c9e05ec0c

See more details on using hashes here.

File details

Details for the file mkdocs_zip_bundle_plugin-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_zip_bundle_plugin-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a802774efdfb26454d608d0318eee663e8aae0ef348659ca2eca759f373e979
MD5 b4912082e64535738c49198776e02251
BLAKE2b-256 82eadb5ca6b08c48a3066c3a3d96c24d1c44f5adef600ba6e393bed52835e40f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page