Gathering detailed insights and metrics for @mdast2docx/image
Gathering detailed insights and metrics for @mdast2docx/image
Gathering detailed insights and metrics for @mdast2docx/image
Gathering detailed insights and metrics for @mdast2docx/image
@m2d/image
MDAST to DOCX plugin for resolving and embedding images. Supports base64, URLs, and custom resolvers for seamless DOCX image integration.
@md2docx/image
MDAST to DOCX plugin for resolving and embedding images. Supports base64, URLs, and custom resolvers for seamless DOCX image integration.
MDAST to DOCX plugin for resolving and embedding images. Supports base64, URLs, and custom resolvers for seamless DOCX image integration.
npm install @mdast2docx/image
Typescript
Module System
Node Version
NPM Version
62.3
Supply Chain
92.5
Quality
82.4
Maintenance
100
Vulnerability
78.4
License
TypeScript (47.45%)
JavaScript (38.71%)
SCSS (11.37%)
Handlebars (2.47%)
Total Downloads
1,345
Last Day
1
Last Week
18
Last Month
114
Last Year
1,345
MPL-2.0 License
1 Stars
490 Commits
1 Watchers
7 Branches
1 Contributors
Updated on Aug 16, 2025
Latest Version
1.3.1
Package Id
@mdast2docx/image@1.3.1
Unpacked Size
29.46 kB
Size
9.98 kB
File Count
15
NPM Version
10.8.2
Node Version
20.19.2
Published on
Jun 12, 2025
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-33.3%
18
Compared to previous week
Last Month
-81%
114
Compared to previous month
Last Year
0%
1,345
Compared to previous year
@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.
1npm install @m2d/image
1pnpm add @m2d/image
1yarn add @m2d/image
The @m2d/image
plugin for mdast2docx
renders image nodes in DOCX output.
It supports:

@m2d/html
@m2d/mermaid
1import { imagePlugin } from "@m2d/image"; 2 3const plugins = [ 4 htmlPlugin(), // Optional — parses HTML <img> into image nodes 5 mermaidPlugin(), // Optional — emits image/svg nodes for diagrams 6 imagePlugin(), // ✅ Must come after HTML/Mermaid plugins 7 tablePlugin(), 8];
🧠 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.
1IImagePluginOptions { 2 /** Scale factor for base64 (data URL) images. @default 3 */ 3 scale?: number; 4 5 /** Fallback format to convert unsupported image types. @default "png" */ 6 fallbackImageType?: "png" | "jpg" | "bmp" | "gif"; 7 8 /** Image resolution function used to convert URL/base64/SVG to image options */ 9 imageResolver?: ImageResolver; 10 11 /** Max image width (in inches) for inserted image */ 12 maxW?: number; 13 14 /** Max image height (in inches) for inserted image */ 15 maxH?: number; 16 17 /** Optional placeholder image (base64 or URL) used on errors */ 18 placeholder?: string; 19 20 /** Enable IndexedDB-based caching. @default true */ 21 idb?: boolean; 22 23 /** 24 * Optional salt string used to differentiate cache keys for similar images (e.g., dark/light theme). 25 */ 26 salt?: string; 27 28 /** Duration in minutes after which cached records are removed as stale. Default: 7 days (10080 minutes). */ 29 maxAgeMinutes?: number; 30 31 /** 32 * Applies generic fixes to known SVG rendering issues (e.g., Mermaid pie chart title alignment). 33 * Designed to be overridden to handle tool-specific quirks in generated SVGs. 34 * 35 * @param svg - Raw SVG string to transform. 36 * @param metadata - Optional metadata such as diagram type or render info. 37 * @returns Modified SVG string. 38 */ 39 fixGeneratedSvg?: (svg: string, metadata: any) => string; 40}
imageResolver
A custom function to fetch or transform the image. Receives the full image
or svg
node.
1imagePlugin({ 2 imageResolver: async (src, options, node) => { 3 const response = await fetch(src); 4 const arrayBuffer = await response.arrayBuffer(); 5 return { 6 type: "png", 7 data: arrayBuffer, 8 transformation: { 9 width: 400, 10 height: 300, 11 }, 12 }; 13 }, 14});
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
No vulnerabilities found.