markdown-image-extractor v1.0.1
Markdown Image Extractor
A simple Node.js tool to extract and download images from markdown files. It’s designed for scenarios where markdown files, such as those from websites like Mathpix, contain images hosted online. This tool downloads those images and updates the markdown to reference local versions instead.
Features
- Extracts image URLs from markdown syntax

. - Detects markdown files dynamically, supporting
.md
,.mdx
, and other variants. - Downloads each image and saves it with a specified prefix.
- Overwrites previously downloaded images without requiring manual cleanup.
- Replaces URLs in the markdown file with local paths, making it easy to host the images locally.
- Full error handling to avoid interruptions, even with invalid URLs or file permissions.
Requirements
- Node.js (v14 or higher recommended)
Installation
npm i -g markdown-image-extractor
Usage
Navigate to the directory with your markdown file(s) and run:
markdown-image-extractor <filename> [prefix]
Replace <filename>
with the markdown file’s name and [prefix]
with a string for naming the downloaded images. If no prefix is provided, it defaults to "img"
.
For example:
markdown-image-extractor filename.md "img"
This command will:
1. Check if the specified file is a markdown-compatible file.
2. Extract all image URLs in the file.
3. Download each image, saving it as img1.jpg
, img2.jpg
, etc., in the current directory.
4. Update the markdown file, replacing each URL with the path to the downloaded image.
Example
Given a markdown file (example.md
) with content like:

Some text.

Running markdown-image-extractor example.md "img"
will:
1. Download the images as img1.jpg
and img2.png
.
2. Update example.md
to:

Some text.

Help
Use the --help
or -h
flag for usage details:
markdown-image-extractor --help
Package Scripts
start
: Runs the script locally (e.g.,node main.js
).lint
: Lints the codebase with ESLint.
License
This project is licensed under the MIT License. See LICENSE for more details.
Issues and Contributions
Please report issues at GitHub Issues. Contributions are welcome!