7/13/2026 at 11:52:14 AM
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!
by fishbone
7/13/2026 at 1:44:10 PM
Sounds to good to be true, but it works for the given examples! What is the scope though? It produces garbage with larger documents with tables and figures. For example this large document, even with removed menu and headings: https://docs.redhat.com/en/documentation/red_hat_enterprise_...Could it be it has only been fed small documents?
by exceptione
7/13/2026 at 2:53:25 PM
All of the suite test cases are small fragments of HTML to test specific things, so I probably do need a way to test bigger documents. Thanks for the feedback. I’ll add that to the to-do list.I’ll try the red hat example later this evening.
by fishbone
7/14/2026 at 8:17:45 AM
Thanks for following up. I don't understand why your post has been flagged.by exceptione
7/14/2026 at 2:40:42 AM
Ok, I dug into the Red Hat doc. It’s a great example and it uncovered a few real shortcomings.A couple of things about this scenario:
First, the page relies on stylesheets, so you need styleSource: "computed", either Playwright on Node, or run in the browser with the content already rendered.
Second, dom-docx doesn’t fetch remote images itself. The caller supplies an imageResolver (e.g. a fetch callback), which keeps security, timeouts, host allowlists, etc. under caller control: https://dom-docx.com/learn#image-resolver
I fixed a few bugs from this (in 0.1.8):
- wide headings inside flex containers getting clipped
- oversized images not scaling down to the printable page width
- OS dark theme (prefers-color-scheme: dark) leaking near-white computed text colors into Word on the browser path
I also added an ad-hoc repo script that loads a live URL, takes a CSS selector, and converts with Playwright (tools/try-url.ts). I used it on the RHEL page and got a pretty decent 200+ page doc. Some tables still look wrong — I’ll dig into those next.
Script: https://github.com/floodtide/dom-docx/blob/main/tools/try-ur...
Example usage from a clone: npx tsx tools/try-url.ts \ "https://docs.redhat.com/en/documentation/red_hat_enterprise_..." \ ".docs-content-container" \ rhel-storage.docx
by fishbone
7/14/2026 at 3:14:17 AM
This is very cool and thanks for sharing the workflow, buuuuuut... Could you please rewrite the README in your own words? If not for this comment, I would have just flagged this submission without looking into it further, because no matter how useful the premise is, it feels like one of the millions “I’ve burnt a bunch of tokens and thrown the result on GitHub” kinda projects you see nowadays. Clearly that’s not the case here, but an LLM-generated README really does your project a disservice.by notpushkin
7/14/2026 at 12:02:04 PM
I hear you, thanks for the feedback. I've done that some already but of course it could be better in more of my own voice.by fishbone
7/13/2026 at 12:25:57 PM
That'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.by Octoth0rpe
7/13/2026 at 4:17:29 PM
In 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.by cgyvbunji
7/13/2026 at 12:47:13 PM
I 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.by fishbone
7/13/2026 at 1:23:12 PM
I 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.
by m_w_
7/13/2026 at 1:32:26 PM
Thanks for the feedback, I’ll add Word validation to my todo list.by fishbone
7/14/2026 at 5:25:25 AM
I 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.by zem
7/14/2026 at 8:06:19 AM
Very interesting approach. I am having trouble with page breaks (documentation says they work, but demo pages dont) etc. For the invoicing example this would require table breaks/overflows into subsequent pages in a real application and I am currently evaluating going with model->PDF or model->DOCXDo you have any approach in this regard that works ?
by mgoetzke
7/14/2026 at 12:08:49 PM
I tested this, but it seems like it regressed somehow. It may not be working in the browser side use case right now. I'll have to look at it later this evening. I created a GH issue to keep it on the radar: https://github.com/floodtide/dom-docx/issues/5Could you update the GH issue with a bit more information about your specific use case?
by fishbone
7/14/2026 at 9:58:40 PM
I fixed this issue. The dom-docx.com Live Converter "Try in the browser" page was running an older version of the dom-docx package from before Page Breaks were added as a feature. I've updated it to the latest version.by fishbone
7/13/2026 at 2:14:22 PM
Interesting but how is an "autoresearch loop" different than creating a spec and X number of testcases and letting an agent run against these testcases and the spec?by rickette
7/13/2026 at 2:57:44 PM
Scoring would probably be the big difference because the outcome is to optimize performance or optimize a score or a metric versus just a pass fail.by fishbone
7/14/2026 at 7:36:55 AM
[flagged]by Sentino_API