mdast2docx logo Md2Docx
Version 0.1.0

Overview

Updated 9 hr ago

CIcodecovnpm versionnpm downloadsnpm bundle sizelicense

@m2d/tiptap: Tiptap extension to export rich-text editor content directly to Word (.docx) documents entirely on the client or server.

✨ Features

  • 📄 Direct DOCX Export: Convert Tiptap rich-text content to Microsoft Word .docx documents.
  • ⚡ Zero Cloud Dependencies: Client-side conversion using @m2d/md2docx without paid subscriptions or external microservices.
  • 🛠️ Seamless Commands: Adds editor.commands.downloadDocx() and editor.commands.getDocxBlob() directly to the Tiptap editor instance.
  • 🎨 Full Document Styling: Configure metadata, headers, footers, margins, page orientation, and embedded plugins (Mermaid diagrams, LaTeX math, rich tables).

📦 Installation

$ pnpm add @m2d/tiptap

or

$ npm install @m2d/tiptap

or

$ yarn add @m2d/tiptap

🚀 Usage

1. Register Extension

import { DocxExtension } from "@m2d/tiptap";
import { useEditor } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";

const editor = useEditor({
  extensions: [
    StarterKit,
    DocxExtension.configure({
      defaultFilename: "my-document.docx",
    }),
  ],
  content: "<h1>Hello World</h1><p>Export me to DOCX!</p>",
});

2. Export / Download DOCX

// Trigger instant browser download:
editor.commands.downloadDocx("custom-name.docx");

// Or obtain raw Blob for custom handling:
const blob = await editor.commands.getDocxBlob({
  docxProps: {
    title: "Quarterly Report",
    creator: "Acme Corp",
  },
});

License

This library is licensed under the MIT open-source license.


with 💖 by Mayank Kumar Chaudhari

On this page