🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@m2d/core

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@m2d/core

Core engine to convert extended MDAST to DOCX. Supports plugins for footnotes, images, lists, tables, and more. Designed for seamless Markdown-to-DOCX conversion.

0.0.5
latest
Source
npm
Version published
Weekly downloads
1.6K
3.74%
Maintainers
1
Weekly downloads
 
Created
Source

@m2d/core

test Maintainability codecov Version Downloads npm bundle size

The core engine that powers mdast2docx — convert Markdown Abstract Syntax Trees (MDAST) into DOCX effortlessly.

✨ Features

  • ✅ Lightweight and fast MDAST to DOCX conversion
  • ✅ Works on both client-side and server-side environments
  • ✅ Built-in support for section-based rendering
  • ✅ Plugin-friendly architecture

Note: With a lean core, functionality can be extended via plugins such as @m2d/html, @m2d/image, @m2d/table, etc.

📦 Installation

pnpm install @m2d/core

or

yarn add @m2d/core

or

npm add @m2d/core

🚀 Usage

import { toDocx } from "@m2d/core";

const docxBlob = await toDocx(mdast, docxProps, sectionProps);

🔌 Plugins

@m2d/core supports both official and community plugins to extend its capabilities. For example:

import { toDocx } from "@m2d/core";
import { imagePlugin } from "@m2d/image";

await toDocx(mdast, docxProps, {
  plugins: [imagePlugin()],
});

🔍 Use only the plugins you need for better performance and bundle size. 🧠 You can use official plugins, or build your own custom ones to keep the bundle size minimal and functionality scoped.

@m2d/core official plugins:

PluginPackagePurpose
HTML@m2d/htmlHandle raw HTML nodes
Image@m2d/imageEmbed images in DOCX
Math@m2d/mathRender LaTeX math
Table@m2d/tableMarkdown tables
List@m2d/listAdvanced list formatting
Extended MDAST@m2d/mdastExtended mdast types

📜 API

toDocx(astInputs, docxProps, defaultSectionProps, outputType?)

ParamTypeDescription
astInputsRoot or { ast: Root; props?: ISectionProps }[]The parsed Markdown AST
docxProps (optional)IDocxPropsDocument metadata and style
defaultSectionProps (optional)ISectionPropsDefault layout configuration for sections
outputType (optional)OutputType(defaults to 'blob')

Returns a Promise resolving to a DOCX Blob, Buffer, or Base64 string.

🤖 Generative AI Use-case

AI tools often generate Markdown — @m2d/core helps convert them into rich DOCX reports or presentations. This is useful in:

  • AI-generated blogs, documentation, and research reports
  • Client-side and server-side rendering of AI-generated content
  • Integrating in GenAI pipelines with format export capabilities

💡 Inspiration & Relevance

This library is especially useful in:

  • Generative AI — Convert Markdown outputs (e.g., from ChatGPT, LLMs) to downloadable DOCX reports
  • Developer Tools — Export Markdown-based documentation or changelogs as DOCX
  • Education — Convert notes, quizzes, or assignments authored in Markdown

✅ Works both on client side and server side — offload to browser or use high-performance Node.js.

🛠️ Development

git clone https://github.com/tiny-md/mdast2docx
cd mdast2docx/m2d/core
pnpm install
pnpm dev

📄 License

Licensed under the MPL-2.0 License.

⭐ Support Us

If you find this useful:

Made with 💖 by Mayank Kumar Chaudhari

with @m2d/core, bring structure, style, and extensibility to your Markdown-to-DOCX pipeline.

Keywords

mdast

FAQs

Package last updated on 12 Apr 2025

Did you know?

Socket

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.

Install

Related posts