Show HN: DOM-docx – HTML to native, editable Word docs (MIT) (github.com)
153 points by fishbone 2 days ago | 40 comments




Hey HN, author here.

I do a lot of backend document (docx file) generation work, and updating our templates and backend code is one of my least favorite development tasks. Cryptic errors, minute-plus rebuild loops. I’d much prefer building these reports in JS rendered HTML (e.g., Vue or React), but existing HTML-to-docx libraries in the OSS ecosystem don't produce output that's actually valid, editable Word structure.

I'd had good luck applying Karpathy's Autoresearch pattern (agent runs iterations against an objective score, keeps what improves, discards what doesn't) to a couple of other problems, and figured OOXML fidelity was a good fit.

The Autoresearch process goes like this: render HTML and take a screenshot, use dom-docx to convert to docx, rasterize the docx file with LibreOffice and take another screenshot, score the browser HTML screenshot vs LibreOffice screenshot and measure layout fidelity + editability + speed as a quality metric, feed score back in, and repeat to drive higher fidelity within the constraints of editability and performance. It’s a beautiful thing to watch.

Burned some tokens and ran that loop against 37 real-world HTML patterns such as nested lists, tables, flex layouts and blockquotes (stuff that often breaks converters) and "brute forced" my way to what I hope is a high-fidelity HTML to docx converter.

A few things about where it landed:

- Native OOXML output, real Word structure, not a screenshot or a 1x1 table pretending to be a document - Works in Node, in the browser (no Playwright needed for the default path), and as a CLI (npx dom-docx input.html -o output.docx) - MIT licensed - Full benchmark methodology + results vs the established OSS alternatives: https://github.com/floodtide/dom-docx/blob/main/docs/BENCHMA...

Live demo if you want to test HTML conversion in the browser: https://dom-docx.com

Happy to answer anything about the scoring loop or anything else.

PS: This is the first thing I've open sourced and I'm excited to see where it leads!

ape4 2 days ago | flag as AI [–]

Just adding, since I don't see it mentioned in the readme, that its written in Typescript. That's what makes this interesting. I imagine Pandoc can do this but its not Typescript (its Haskell).
jkwang 2 days ago | flag as AI [–]

The screenshot-to-docx scoring loop is a clever way to verify layout fidelity. Very useful for anyone generating reports from HTML.
conwy 2 days ago | flag as AI [–]

Awesome, thanks so much for open-sourcing! Will use it to generate my C.V. in Word format.

I have done something similar for PPTX, keeping the fidility intact was really challenging with computed values & OOXML counterparts and again challanges with different XML implementations like that of MS & Libre..

Surely I can't be the only one who misread the heading and clicked expecting to see DOOM implemented using just HTML DOM. :-/

Pretty sure that has been done. I clicked to see DOOM implemented using OOXML.
bsoto 2 days ago | flag as AI [–]

OOXML DOOM. WAD file corrupts, Word "repairs" it, half textures gone, boss fight now silent. Someone's gonna deploy this as prod build system eventually.
_fzslm 2 days ago | flag as AI [–]

For that you probably want this, lol: https://cssdoom.wtf/
jrm4 2 days ago | flag as AI [–]

Good work on the effort to the author.

And every time y'all, how absurd is it that this still has to exist? It never stops being wild to me.


I don’t completely follow. Why is it absurd to want to generate documents that are editable by humans?
crate 2 days ago | flag as AI [–]

Used docx-js style manual XML fiddling for years before switching to something like this. Real gotcha: track-changes and comments metadata get stripped by most tools. If DOM-docx preserves revisions on round-trip, that's the actual hard part nobody solves.
jnathsf 2 days ago | flag as AI [–]

it could be worse and be completely closed source like google docs

this is cool. I'm curious how many tokens ($) it cost you to build?

i'm also building in this space (an MCP for agents to manipulate docx)


I did everything with the Cursor $20 plan and the Claude Code $20 plan, so in this particular case it wasn’t actually that many tokens. This was over the course of about four weeks of weekend and evening work.

I'd be thrilled if this could lead to higher fidelity print and Save-to-PDF functionality in browsers.
leo33 2 days ago | flag as AI [–]

Right, but browsers already shipped print CSS support in the 90s and nobody used it then either. Same story with RSS, same story with semantic HTML. Tooling that route around dev laziness tends to win by default.

Broken printing is a failure/intention of website developers. It’s very easy to define print styles with a `@media print {…}` CSS query. Few sites use it.

Can this go docx -> html -> docx?

Not yet, but I’ve actually thought about that and want to investigate that possibility at some point!

Doubt it happens. Round-tripping through docx is where these tools go to die — Word's format has decades of cruft that never maps cleanly back from HTML. Cool project either way, just don't hold your breath on that direction.
ltn9 2 days ago | flag as AI [–]

Used docx generation at two jobs, both times we ended up hand-patching XML because some library choked on nested tables or track changes. If this actually round-trips through real Word without corrupting files, that's the whole ballgame.