
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@m2d/image
Advanced tools
MDAST to DOCX plugin for resolving and embedding images. Supports base64, URLs, and custom resolvers for seamless DOCX image integration.
@m2d/image
Converts Markdown (

), HTML<img>
, and customimage
/svg
nodes into DOCX-compatibleImageRun
elements.
Parsing HTML or Mermaid to SVG or image tags requires
@m2d/html
or@m2d/mermaid
, respectively.
However,@m2d/image
handles all image rendering to DOCX regardless of origin.
npm install @m2d/image
pnpm add @m2d/image
yarn add @m2d/image
The @m2d/image
plugin for mdast2docx
renders image nodes in DOCX output.
It supports:

@m2d/html
@m2d/mermaid
import { imagePlugin } from "@m2d/image";
const plugins = [
htmlPlugin(), // Optional — parses HTML <img> into image nodes
mermaidPlugin(), // Optional — emits image/svg nodes for diagrams
imagePlugin(), // ✅ Must come after HTML/Mermaid plugins
tablePlugin(),
];
🧠 If using
@m2d/html
or@m2d/mermaid
, place them before this plugin. They generateimage
orsvg
nodes, but only@m2d/image
renders them to DOCX.
This plugin is production-grade, supporting all major image scenarios:
data-*
attributes from HTML💬 We welcome feedback, bugs, and contributions — open an issue or PR anytime.
IImagePluginOptions {
/** Scale factor for base64 (data URL) images. @default 3 */
scale?: number;
/** Fallback format to convert unsupported image types. @default "png" */
fallbackImageType?: "png" | "jpg" | "bmp" | "gif";
/** Image resolution function used to convert URL/base64/SVG to image options */
imageResolver?: ImageResolver;
/** Max image width (in inches) for inserted image */
maxW?: number;
/** Max image height (in inches) for inserted image */
maxH?: number;
/** Optional placeholder image (base64 or URL) used on errors */
placeholder?: string;
/** Enable IndexedDB-based caching. @default true */
idb?: boolean;
/**
* Optional salt string used to differentiate cache keys for similar images (e.g., dark/light theme).
*/
salt?: string;
/** Duration in minutes after which cached records are removed as stale. Default: 7 days (10080 minutes). */
maxAgeMinutes?: number;
/**
* Applies generic fixes to known SVG rendering issues (e.g., Mermaid pie chart title alignment).
* Designed to be overridden to handle tool-specific quirks in generated SVGs.
*
* @param svg - Raw SVG string to transform.
* @param metadata - Optional metadata such as diagram type or render info.
* @returns Modified SVG string.
*/
fixGeneratedSvg?: (svg: string, metadata: any) => string;
}
imageResolver
A custom function to fetch or transform the image. Receives the full image
or svg
node.
imagePlugin({
imageResolver: async (src, options, node) => {
const response = await fetch(src);
const arrayBuffer = await response.arrayBuffer();
return {
type: "png",
data: arrayBuffer,
transformation: {
width: 400,
height: 300,
},
};
},
});
You don’t need to implement caching — it’s handled internally with persistent storage. And it is configurable!
placeholder
Used if the image fails to load or decode. Can be:
idb
Whether to enable IndexedDB caching (in addition to in-memory).
true
(default): uses IndexedDBfalse
: disables persistent cacheimage
and svg
nodesimageResolver
docx.ImageRun
, including alt text and limited styles
<img>
, <svg>
support via @m2d/html
@m2d/mermaid
or custom pluginsdata-*
<canvas>
, <img>
, etc.)object-fit
, fitWidth
, and complex layout constraints are not supportedPlugin | Purpose |
---|---|
@m2d/core | Converts extended MDAST to DOCX |
@m2d/html | Parses raw HTML to extended MDAST |
@m2d/mermaid | Adds mermaid diagrams as SVG/image nodes |
@m2d/table | Renders table nodes to DOCX |
@m2d/list | Enhanced list support (tasks, bullets) |
If you find this useful:
MIT © Mayank Chaudhari
Made with 💖 by Mayank Kumar Chaudhari
FAQs
MDAST to DOCX plugin for resolving and embedding images. Supports base64, URLs, and custom resolvers for seamless DOCX image integration.
The npm package @m2d/image receives a total of 3,935 weekly downloads. As such, @m2d/image popularity was classified as popular.
We found that @m2d/image demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.