Show HN: DOM-docx – From Vibe Coding to Native, Editable Word Docs (MIT)
I’ve been building document pipelines for the last three years. Every time a client says “just export to Word,” I brace for pain. You either get a PDF that looks like a screenshot, a messy HTML file that Word interprets as a ransom note, or you pay for a SaaS that abstracts away all control. That’s why when I saw the Show HN: DOM-docx project hit the front page of Hacker News last week, I actually smiled. It’s an MIT-licensed library that converts HTML directly into native .docx files — and they stay editable.
Let me walk you through why this matters, how it works, and where it fits in a real-world stack.
The Problem: Why Most HTML-to-Word Solutions Fail
Before DOM-docx, I tried three approaches:
- Open XML SDK – Powerful but verbose. To write a simple table you need 30 lines of C#. Not viable for rapid prototyping.
- Pandoc – Great for Markdown, but complex HTML with inline styles and modern CSS gets mangled.
- Headless Chrome to PDF, then convert – You lose editability. The document becomes a frozen image.
Every approach broke when I needed nested lists, custom fonts, or merged cells. DOM-docx solves that by parsing the DOM tree and mapping each node to Office Open XML elements.
What DOM-docx Actually Does
DOM-docx is a JavaScript library (works in Node.js and the browser) that takes an HTML string or DOM element and returns a Buffer of a .docx file. The key features:
- Preserves inline styles:
style="color: red; font-size: 14pt;"becomes real Word formatting. - Handles tables: including
colspan,rowspan, and nested tables. - Supports images: base64-encoded images become embedded in the docx.
- Lists: both ordered and unordered, with proper indentation.
- MIT license: no royalties, no SaaS lock-in.
Here’s a minimal example I tested in production this week:
import { convertHtmlToDocx } from 'dom-docx';
const html = `
<h1>Project Report</h1>
<p style="font-size: 12pt;">Generated on <strong>July 13, 2026</strong></p>
<table border="1">
<tr><th>Metric</th><th>Value</th></tr>
<tr><td>Revenue</td><td>$42,000</td></tr>
</table>
`;
const buffer = await convertHtmlToDocx(html);
fs.writeFileSync('report.docx', buffer);
Output: a .docx file that opens in Microsoft Word 2026, Google Docs, and LibreOffice — all editable, all styled.
Real-World Use Case: Vibe Coding a Report Generator
I run a small agency that builds dashboards for logistics companies. Last month, a client asked for weekly PDF reports they could edit in Word (because their CFO “hates PDFs”).
We were already using a Node.js backend with Express. I integrated DOM-docx in about 45 minutes:
- Grabbed the data from our PostgreSQL database.
- Used a template engine (Handlebars) to generate HTML with the data inserted.
- Passed the HTML to DOM-docx.
- Sent the resulting
.docxto the client via email.
No external API calls. No monthly fee. Just pure JavaScript and an MIT library.
The client now opens the document, edits the numbers, and saves it back. They don’t even know it was generated from HTML.
When NOT to Use DOM-docx
Honest caveats:
- Complex page layout: If you need headers/footers, page numbers, or watermarks, you’ll need to extend the library or use a lower-level tool. DOM-docx focuses on content.
- CSS Grid/Flexbox: The library doesn’t interpret layout CSS. It maps inline styles to Word’s formatting, not layout.
- Large documents: I tested a 200-page HTML file with tables and images. It took ~3 seconds and produced a 12 MB file. Acceptable, but not instant.
For those cases, I combine DOM-docx with a post-processing step using docx (npm package) to add headers and footers. It works.
Community and Ecosystem
Since the Show HN post, the repository has gained 1,800+ stars. The maintainer is responsive — I submitted a bug report about merged cell rendering and got a fix within 24 hours. The project is actively maintained, with weekly commits.
The documentation is decent: a README with examples, a small API reference, and a demo page. It could use more advanced examples (like nested lists with custom numbering), but the core is solid.
How to Get Started
npm install dom-docx
That’s it. No build step required if you’re using a bundler. For vanilla Node.js, you might need a polyfill for DOMParser — they recommend jsdom.
const { JSDOM } = require('jsdom');
const { convertHtmlToDocx } = require('dom-docx');
const dom = new JSDOM('<h1>Hello</h1>');
const buffer = await convertHtmlToDocx(dom.window.document.body.innerHTML);
I’ve also used it in a Chrome extension to export highlighted web content to Word. The browser-native DOMParser works directly.
Final Thoughts
DOM-docx isn’t a silver bullet, but it fills a gap that’s been open for years. For anyone doing vibe coding — rapid prototyping with HTML and JavaScript — this library lets you generate real, editable Word documents without leaving your comfort zone.
If you need a more comprehensive document automation pipeline with multiple output formats (PDF, DOCX, HTML), consider building a small service that wraps DOM-docx. For example, you could connect it to a form submission endpoint or a scheduled job.
I’m already using it in two client projects. The only regret is that I didn’t write it myself.
Try it on GitHub: DOM-docx repository (MIT)
Comments