Mammoth.js

Convert Word .docx documents into clean, semantic HTML and Markdown in JavaScript.

Library
npm
v1.13.0
6,333 stars
BSD-2-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
85 /100 Excellent
Development Activity 96
Maintenance 72
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
81 /100 Excellent
Architecture 82
Code Quality 83
Innovation 86
Learning Curve 85

Mammoth.js converts Word .docx documents — including those authored in Microsoft Word, Google Docs, and LibreOffice — into clean, semantic HTML rather than a pixel-perfect copy of the original formatting. It leans on the document’s semantic styles, mapping a paragraph styled as “Heading 1” to an h1 element instead of trying to reproduce fonts, sizes, and colors, which keeps the generated markup simple and predictable.

The library runs in both Node.js and the browser and ships with a CLI, a promise-based API, and a small style-map DSL that lets you customize how your own document styles translate to HTML. It supports headings, lists, tables, footnotes, images, links, comments, and common inline formatting, making it a practical tool for ingesting Word content into web applications and content pipelines.

What You Get

  • A promise-based convertToHtml / convertToMarkdown / extractRawText API for Node.js and the browser
  • A mammoth CLI for converting documents and exporting images to a directory
  • A customizable style-map DSL for mapping your own Word styles to specific HTML elements and classes
  • Support for headings, lists, tables, footnotes, endnotes, images, links, comments, and inline formatting
  • Pluggable image converters for controlling how embedded images are emitted (inline data URIs or external files)

Common Use Cases

  • Importing Word documents authored by non-technical users into a CMS or web application
  • Building content pipelines that normalize .docx uploads into semantic HTML
  • Extracting raw text from Word documents for search indexing or analysis
  • Mapping bespoke corporate Word styles to a consistent set of HTML components

Under The Hood

Architecture

Mammoth is organized as a clean multi-stage pipeline centered on lib/index.js, which orchestrates conversion via convert(). Input is opened with lib/unzip.js (a .docx is a zip archive), then lib/docx/docx-reader.js and its collaborators — body-reader.js, document-xml-reader.js, notes-reader.js, styles-reader.js, numbering-xml.js, and relationships-reader.js — parse the OOXML parts into an internal document model defined in lib/documents.js. The parsed document is then handed to DocumentConverter in lib/document-to-html.js, which applies the resolved style map and emits output through pluggable writers in lib/writers/ (HTML or Markdown). Style mappings are parsed by lib/style-reader.js using the lop parser-combinator DSL, and results/warnings flow through a Result monad in lib/results.js that threads conversion messages alongside values.

Tech Stack

Written in JavaScript (99.5% of the repo) targeting Node.js >=12. Core runtime dependencies include @xmldom/xmldom for XML parsing, jszip for reading the zip container, bluebird for promises, lop for the style-map grammar, underscore for utilities, argparse for the CLI, plus base64-js, dingbat-to-unicode, path-is-absolute, and xmlbuilder. Browser builds are produced with browserify, and a browser/ directory provides browser-specific implementations of unzip.js and docx/files.js via the package’s browser field.

Code Quality

The project is well tested: 33 .tests.js suites run under Mocha with hamjest/duck matchers, covering the readers, converters, style parsing, images, and raw-text extraction. ESLint runs as a pretest step, and error handling is disciplined — rather than throwing on recoverable issues, conversions accumulate warnings through the Result type and return them alongside the output, giving callers structured feedback. A hand-written lib/index.d.ts provides TypeScript types.

API Design The public API is small and ergonomic: a handful of promise-returning functions (convertToHtml, convertToMarkdown, extractRawText) take a simple input descriptor ({path}, {buffer}, or {arrayBuffer}) and an options object. Getting started requires almost no boilerplate, while the string- or array-based styleMap option and pluggable convertImage handlers offer deep customization without complicating the common case. The README is thorough, with extensive examples and a full style-map syntax reference.

Used by 25 apps in this directory

TypeScript
91%
Other

FastGPT

AI Agents · AI Development

29,900

Build, debug, and deploy knowledge-based AI agents with a visual workflow editor, RAG retrieval, and support for any OpenAI-compatible LLM.

View details
93
Repo Health
84
Technical
66
Dependency
Built with
TypeScript 91%
Updated 5 days ago
TypeScript
62%
Other

Flowise

AI Development · Automation · Developer Tools

55,521

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
75
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 62%
JavaScript 27%
Updated 2 months ago
TypeScript
62%
EPL-2.0

Huly Platform

Collaboration · Project Management · Team Chat

27,978

Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.

View details
90
Repo Health
86
Technical
62
Dependency
Built with
TypeScript 62%
Svelte 34%
Updated 6 days ago
TypeScript
100%
Apache 2.0

ILLA Builder

Design Tools · Developer Tools · Low Code Platforms

12,333

Open-source low-code platform for building internal tools with drag-and-drop UI, reactive data bindings, and real-time collaboration.

View details
55
Repo Health
71
Technical
63
Dependency
Built with
TypeScript 100%
Updated 5 months ago
TypeScript
100%
MIT

JobSync

AI Assistants · Productivity

1,445

The self-hosted job search assistant that tracks applications, reviews resumes with AI, and auto-discovers matching roles from Greenhouse, Lever, and Ashby boards — all while keeping your data on your own server.

View details
84
Repo Health
79
Technical
70
Dependency
Built with
TypeScript 100%
Updated 6 days ago
TypeScript
85%
MIT

LibreChat

AI Assistants · Developer Tools

46,236

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
62
Dependency
Built with
TypeScript 85%
JavaScript 14%
Updated 5 days ago
TypeScript
98%
Other

LobeHub

AI Assistants · Automation · Productivity

83,455

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
96%
AGPL 3.0

Midday

Invoicing Finance · Productivity

15,091

All-in-one AI-powered business operations platform for freelancers and solo entrepreneurs to manage invoicing, time tracking, banking, and financial intelligence.

View details
51
Repo Health
78
Technical
67
Dependency
Built with
TypeScript 96%
Updated 4 months ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

208,437

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
62
Dependency
Built with
TypeScript 92%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers