Markdown Image Base64
简体中文 | English
A VS Code extension that converts pasted images into Base64 data URLs and inserts them into Markdown using reference-style syntax.
Features
- Paste screenshots or copied image data into Markdown.
- Paste or drop image files, local image paths, file URIs, and remote image URLs.
- Keep Markdown readable by inserting a short image reference at the cursor and storing the Base64 definition at the end of the document.
- Reuse an existing definition when the same image data is pasted again.
- Optionally remove plugin-managed definitions after their final image reference is deleted.
- Convert every supported local or remote image link in the current Markdown document in one command.
Supported formats are PNG, JPEG, GIF, WebP, BMP, and SVG.
Use Ctrl+Alt+V on Windows/Linux or Cmd+Alt+V on macOS to explicitly select the Base64 paste action. Normal paste also offers the action when VS Code detects supported image data.
Run Markdown Image Base64: Convert All Images to Base64 from the Command Palette to convert image links throughout the current saved Markdown file. The command supports inline images and reference-style images. Relative local paths are resolved from the Markdown file's directory. Failed images remain unchanged while successfully loaded images are converted, and the complete document update can be undone as one edit.
How It Works
The extension checks clipboard data in this order:
- Image MIME entries.
- File-backed clipboard entries.
- Local or remote entries in
text/uri-list.
- A local image path or remote image URL in
text/plain.
New content uses this format:
![image][^img_1720000000000]
<!-- markdown-image-base64:managed ^img_1720000000000 -->
[^img_1720000000000]: data:image/png;base64,iVBORw0K...
The HTML comment marks the definition as managed by this extension. Automatic cleanup only removes marked definitions whose label matches the adjacent definition and no longer has an image reference. Unmarked definitions, including definitions created by older versions, are never automatically removed.
If no supported image source is found, VS Code's default paste behavior is preserved.
Requirements
- VS Code 1.97.0 or newer.
- Markdown files must use the
file URI scheme. Untitled and virtual documents are not handled.
Extension Settings
markdown-image-base64.removeOrphanedBase64 (default: true): Remove a plugin-managed Base64 definition after its final Markdown image reference is deleted. Disable this if definitions should only be removed manually.
Resource and Network Limits
- Local and remote images are limited to 10 MiB before Base64 encoding.
- Local files are read asynchronously.
- Remote downloads have a 10-second total timeout and follow at most five redirects.
- Remote responses must use a supported image
Content-Type; missing or non-image content types are rejected.
- Only HTTP and HTTPS remote URLs are supported.
Base64 encoding increases the stored image size by roughly one third, so even accepted images can make Markdown documents large.
Known Limitations
- Remote URLs are considered only when their path ends in a supported image extension. Query parameters are allowed.
- The whole-document conversion command accepts remote image URLs without a file extension and validates them using the response
Content-Type.
- Images inside fenced code blocks, inline code, and HTML comments are intentionally ignored.
- Existing unmarked definitions are preserved and must be removed manually.
- SVG content is embedded as provided.
Release Acceptance Checklist
Before publishing, manually verify on each supported operating system where practical:
- Paste a screenshot from the system clipboard.
- Paste and drag an image file from the file explorer.
- Paste a local path containing spaces and non-ASCII characters.
- Paste a remote URL that redirects to a supported image.
- Paste with multiple cursors and confirm one definition is appended.
- Delete the final image reference and verify only its marked definition is removed.
- Disable
removeOrphanedBase64 and verify definitions remain.
Development
pnpm install
pnpm run check-types
pnpm run compile
pnpm test
Changelog
See CHANGELOG.md for release history.
License
MIT