mdctl
A command-line tool for processing Markdown files. Currently, it supports automatically downloading remote images to local storage and updating the image references in Markdown files.
Features
- Supports processing individual Markdown files or entire directories (including subdirectories).
- Automatically downloads remote images to a specified local directory.
- Preserves original image filenames (where available).
- Handles duplicate filenames automatically.
- Updates image references in Markdown files using relative paths.
- Provides detailed processing logs.
Installation
use Homebrew to install mdctl. Follow the Homebrew Installation Guide to install Homebrew.
bash
brew tap samzong/tap
brew install samzong/tap/mdctlor use go to install mdctl.
bash
go install github.com/samzong/mdctl@latestUsage
Downloading Remote Images
Processing a single file:
bash
mdctl download -f path/to/your/file.mdProcessing an entire directory:
bash
mdctl download -d path/to/your/directorySpecifying an output directory for images:
bash
mdctl download -f path/to/your/file.md -o path/to/imagesCommand Reference
download Command
Downloads and localizes remote images in Markdown files.
Parameters:
-f, --file: Specifies the Markdown file to process.-d, --dir: Specifies the directory to process (recursively processes all Markdown files).-o, --output: Specifies the directory for saving images (optional).- Default:
imagessubdirectory within the file's directory (file mode). - Default:
imagessubdirectory within the specified directory (directory mode).
- Default:
Notes
-fand-dparameters cannot be specified simultaneously.- If no output directory is specified, the tool will automatically create a default
imagesdirectory. - The tool processes only remote images (http/https); local image references are not modified.
- Image filenames are preserved; if duplicates are encountered, the URL's hash value is appended as a suffix.