HackerTrans
TopNewTrendsCommentsPastAskShowJobs

fishbone

146 karmajoined 8 lat temu

Submissions

Show HN: DOM-docx – HTML to native, editable Word docs (MIT)

github.com
149 points·by fishbone·wczoraj·39 comments

Show HN: Wealth Curve – Financial forecasting with local storage and E2EE

wealthcurve.app
1 points·by fishbone·3 miesiące temu·0 comments

comments

fishbone
·3 godziny temu·discuss
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/5

Could you update the GH issue with a bit more information about your specific use case?
fishbone
·3 godziny temu·discuss
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.
fishbone
·12 godzin temu·discuss
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
fishbone
·19 godzin temu·discuss
Since 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.
fishbone
·20 godzin temu·discuss
Not yet, but I’ve actually thought about that and want to investigate that possibility at some point!
fishbone
·24 godziny temu·discuss
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.
fishbone
·24 godziny temu·discuss
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.
fishbone
·24 godziny temu·discuss
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.
fishbone
·wczoraj·discuss
Thanks, 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
fishbone
·wczoraj·discuss
Thanks for the feedback, I’ll add Word validation to my todo list.
fishbone
·wczoraj·discuss
Agreed, visual fidelity is pretty hard, and that’s why none of the scores are 100.
fishbone
·wczoraj·discuss
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.
fishbone
·wczoraj·discuss
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!