npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@docen/export-docx

v0.0.9

Published

A powerful TipTap/ProseMirror extension that converts editor content to Microsoft Word DOCX format

Readme

@docen/export-docx

npm version npm downloads npm license

Export TipTap/ProseMirror editor content to Microsoft Word DOCX format.

Features

  • 📝 Rich Text Support - Full support for headings, paragraphs, and blockquotes with proper formatting
  • 🖼️ Image Handling - Automatic image sizing, positioning, and metadata extraction
  • 📊 Table Support - Complete table structure with headers, cells, colspan, and rowspan
  • Lists & Tasks - Bullet lists, numbered lists with custom start numbers, and task lists with checkboxes
  • 🎨 Text Formatting - Bold, italic, underline, strikethrough, subscript, and superscript
  • 🎯 Text Styles - Comprehensive style support including colors, backgrounds, fonts, sizes, and line heights
  • 🔗 Links - Hyperlink support with href preservation
  • 💻 Code Blocks - Syntax highlighted code blocks with language attribute support
  • 📁 Collapsible Content - Details/summary sections for expandable content
  • 😀 Emoji Support - Native emoji rendering in documents
  • 🧮 Mathematical Content - LaTeX-style formula support
  • ⚙️ Configurable Options - Customizable export options for documents, tables, styles, and horizontal rules

Installation

# Install with npm
$ npm install @docen/export-docx

# Install with yarn
$ yarn add @docen/export-docx

# Install with pnpm
$ pnpm add @docen/export-docx

Quick Start

import { generateDOCX } from "@docen/export-docx";
import { writeFileSync } from "node:fs";

// Your TipTap/ProseMirror editor content
const content = {
  type: "doc",
  content: [
    {
      type: "paragraph",
      content: [
        {
          type: "text",
          marks: [{ type: "bold" }, { type: "italic" }],
          text: "Hello, world!",
        },
      ],
    },
  ],
};

// Convert to DOCX and save to file
const docx = await generateDOCX(content, { outputType: "nodebuffer" });
writeFileSync("document.docx", docx);

API Reference

generateDOCX(content, options)

Converts TipTap/ProseMirror content to DOCX format.

Parameters:

  • content: JSONContent - TipTap/ProseMirror editor content
  • options: DocxExportOptions - Export configuration options

Returns: Promise<OutputByType[T]> - DOCX file data with type matching the specified outputType

Available Output Types:

  • "base64" - Base64 encoded string
  • "string" - Text string
  • "text" - Plain text
  • "binarystring" - Binary string
  • "array" - Array of numbers
  • "uint8array" - Uint8Array
  • "arraybuffer" - ArrayBuffer
  • "blob" - Blob object
  • "nodebuffer" - Node.js Buffer

Configuration Options:

  • title - Document title
  • creator - Document author
  • description - Document description
  • outputType - Output format (required)
  • table - Table styling defaults (alignment, spacing, borders)
  • image - Image handling options
  • styles - Document default styles (font, line height, spacing)
  • horizontalRule - Horizontal rule style

Supported Content Types

Text Formatting

  • Bold, Italic, Underline, ~~Strikethrough~~
  • ^Superscript^ and ~Subscript~
  • Text colors and background colors
  • Font families and sizes
  • Line heights

Block Elements

  • Headings (H1-H6) with level attribute
  • Paragraphs with text alignment (left, right, center, justify)
  • Blockquotes (Note: Exported as indented paragraphs with left border due to DOCX format)
  • Horizontal Rules (Exported as page breaks by default)
  • Code Blocks with language support

Lists

  • Bullet Lists - Standard unordered lists
  • Numbered Lists - Ordered lists with custom start number
  • Task Lists - Checkbox lists with checked/unchecked states

Tables

  • Complete table structure with rows and cells
  • Table Headers with colspan/rowspan support
  • Table Cells with colspan/rowspan support
  • Cell alignment and formatting options

Media & Embeds

  • Images with automatic sizing and positioning
  • Links (hyperlinks) with href attribute
  • Emoji rendering
  • Mathematics formulas (LaTeX-style)
  • Details/Summary collapsible sections

Examples

Document with Tables and Colspan/Rowspan

const content = {
  type: "doc",
  content: [
    {
      type: "table",
      content: [
        {
          type: "tableRow",
          content: [
            {
              type: "tableHeader",
              attrs: { colspan: 2, rowspan: 1 },
              content: [
                {
                  type: "paragraph",
                  content: [{ type: "text", text: "Spanning Header" }],
                },
              ],
            },
            {
              type: "tableCell",
              content: [
                {
                  type: "paragraph",
                  content: [{ type: "text", text: "Regular Cell" }],
                },
              ],
            },
          ],
        },
      ],
    },
  ],
};

Document with Text Styles

const content = {
  type: "doc",
  content: [
    {
      type: "paragraph",
      content: [
        {
          type: "text",
          marks: [
            {
              type: "textStyle",
              attrs: {
                color: "#FF0000",
                fontSize: "18px",
                fontFamily: "Arial",
                backgroundColor: "#FFFF00",
              },
            },
          ],
          text: "Red, 18px, Arial text on yellow background",
        },
      ],
    },
  ],
};

Document with Lists

const content = {
  type: "doc",
  content: [
    {
      type: "bulletList",
      content: [
        {
          type: "listItem",
          content: [
            {
              type: "paragraph",
              content: [{ type: "text", text: "First item" }],
            },
          ],
        },
        {
          type: "listItem",
          content: [
            {
              type: "paragraph",
              content: [{ type: "text", text: "Second item" }],
            },
          ],
        },
      ],
    },
  ],
};

Known Limitations

Blockquote Structure

DOCX does not have a semantic blockquote structure. Blockquotes are exported as:

  • Indented paragraphs (720 twips / 0.5 inch left indentation)
  • Left border (single line)

This is a DOCX format limitation, not a bug.

Code Marks

The code mark is exported as monospace font (Consolas). When re-importing, it will be recognized as textStyle with fontFamily: "Consolas", not as a code mark.

This is intentional - we do not detect code marks from fonts during import to avoid false positives.

Color Name Conversion

Color names (like "red", "green", "blue") are automatically converted to hex values ("#FF0000", "#008000", "#0000FF") for DOCX compatibility.

Contributing

Contributions are welcome! Please read our Contributor Covenant and submit pull requests to the main repository.

License