5 ms·
Show HN: DOM-docx – HTML to native, editable Word docs (MIT)
- eagleinparadise 3mo agoCan this go docx -> html -> docx?
- fishbone 3mo agoNot yet, but I’ve actually thought about that and want to investigate that possibility at some point!
- fishbone 3mo agoHey 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/BENCHMARK.md 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 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!
- Octoth0rpe 3mo agoThat's an interesting approach. I'm concerned about the use of LibreOffice as your source of truth. Would it be possible to swap out LibreOffice for actual MS Word in this workflow? This also could reveal some libreoffice rendering bugs/edge cases that are worth filing bugs over.
- fishbone 3mo agoI don’t have MS word installed on my development machine, so I haven’t done much testing with Word, but that does sound like a good idea to run the suite using Word. For what it’s worth I did not notice any issues with LibreOffice, even after running many iterations and tests.
- m_w_ 3mo agoI would add a +1 for testing w/ Word - the official Office suite runs some validation where only Word will show a "broken file" popup, even when nothing else does. In our case, clients use only real Word, so any machine-generated/mutated files (excel/ppt as well) need a pass through the real office executable.
- fishbone 3mo agoThanks for the feedback, I’ll add Word validation to my todo list.
- cgyvbunji 3mo agoIn my experience a docx that looks good in libreoffice usually looks good in word, it's the other way around that is usually more of a problem.
- zem 3mo agoI spent two days last week trying to figure out why a docx file I was generating with python-docx looked fine in libreoffice but would not open in word. it was just some text with a circle overlaid on it, but word is a lot fussier about the xml structure of the document than libreoffice is. finally had to create the same structure directly in msword and have claude examine the two files for differences.
- noufalibrahim 3mo agoSurely I can't be the only one who misread the heading and clicked expecting to see DOOM implemented using just HTML DOM. :-/
- virajk_31 3mo agoI 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..
- fishbone 3mo agoAgreed, visual fidelity is pretty hard, and that’s why none of the scores are 100.
- ape4 3mo agoJust 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).
- w10-1 3mo agopandoc purportedly can run as wasm: https://github.com/haskell-wasm/pandoc-wasm https://github.com/haskell-wasm/pandoc-wasm
- jkwang 3mo agoThe screenshot-to-docx scoring loop is a clever way to verify layout fidelity. Very useful for anyone generating reports from HTML.
- fishbone 3mo agoThanks, and just to mention, I’ve had awesome results using Autoresearch loops on other things like SQL performance. Prompt example: You are a SQL performance researcher. Run the following SQL query to establish a baseline, then come up with hypotheses to improve performance. Score each result and run 5 iterations. Avoid any regressions, each result must contain the exact same rows and columns. See https://github.com/karpathy/autoresearch https://github.com/karpathy/autoresearch
- patates 3mo agoAlso works wonderful for generating AI scripts, goal being increasing the elo rating after a tournament run. Also having deep and shallow tests save a lot of time. Deep tests are run sparingly while shallow tests are run after each change.
- qiaobax 3mo ago[dead]
- topaztee 3mo agothis 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)
- fishbone 3mo agoI 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.
- jrm4 3mo agoGood 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.
- skrebbel 3mo agoI don’t completely follow. Why is it absurd to want to generate documents that are editable by humans?
- jrm4 3mo agoNo, I mean it's absurd that a horrible "standard" like a Word Doc has such staying power, and that we have to keep writing things against it.
- fishbone 3mo agoSince HTML is so rich and the DX is amazing these days, I wish HTML file sharing for the document use case (and using the browser as a client) was widely accepted, it’s another problem/opportunity I’ve pondered a lot.
- jnathsf 3mo agoit could be worse and be completely closed source like google docs
- conwy 3mo agoAwesome, thanks so much for open-sourcing! Will use it to generate my C.V. in Word format.
- rkagerer 3mo agoI'd be thrilled if this could lead to higher fidelity print and Save-to-PDF functionality in browsers.
- anon373839 3mo agoBroken 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.