Show HN: HTML-to-Markdown – convert entire websites to Markdown with Golang/CLI (github.com)
Hey HN!
I originally built “html-to-markdown” back in 2018 (while still in high school) to handle complex HTML conversions where other libraries struggled.
Now, I’ve released v2 — a complete rewrite designed to handle even more edge cases. It supports entire websites with a high accuracy.
Example use: I’ve used it in my RSS reader to strip HTML down to clean Markdown, similar to the "Reader Mode" in your Browser.
It can be used as a Golang package or as an CLI.
Give it a try & tell me what edge cases you encounter!
48 comments
[ 3.2 ms ] story [ 97.0 ms ] threadI built something similar for the Elixir world but it’s much more limited (I might borrow some of your ideas):
https://github.com/agoodway/html2markdown
Use https://tools.simonwillison.net/jina-reader to fetch the https://news.ycombinator.com/ homepage as Markdown and paste it into https://tools.simonwillison.net/claude-token-counter - 1550 tokens.
Same thing as HTML: 13367 tokens.
Possible approaches include transforming the text to MD or minimizing the HTML (e.g., removing script tags, comments, etc.).
I'd love to figure out a way to do it though, it seems to me that there's a bunch of rich description of the website in the html
We interact with the web so much that it’s worth having such a library in every language... Great that you took the time and wrote one for the Elixir community!
Feel free to contact me if you want to ping-pong some ideas!
> feeding LLMs web page data
Exactly, that one use case that got quite popular. There is also the feature of keeping specific HTML tags (e.g. <article> and <footer>) to give the LLM a bit more context about the page.
Fresh tools and more choice is very welcome, thanks for your work!
And their html to markdown converter is (in my opinion) still the best right now.
But html-to-markdown is getting close. My goal is to cover more edge cases than pandoc...
https://farnots.github.io/RedditToMarkdown/
https://urltomarkdown.com/
Incredibly useful for leveraging LLMs and building AI apps.
If you're already running a headless browser you may as well run the conversion in JavaScript though - I use this recipe pretty often with my shot-scraper tool: https://shot-scraper.datasette.io/en/stable/javascript.html#... - adding https://github.com/mixmark-io/turndown to the mix will get you Markdown conversion as well.
But nowadays—with Playwright and Puppeteer—there are great choices for Browser automation.
That’s actually a great idea!
I personally use Raindrop for bookmarking articles. But I can’t find stuff in the search.
The other day “Embeddings are underrated” was on HN. That would actually be a good approach for finding stuff later on. Using webhooks, converting to markdown, generating embedding and then enjoying a better search. You just gave me the idea for my next weekend project :-)
I wonder if it is feasible to use this as a replacement for p2k, instapaper etc for the purpose of reading on Kindle. One annoyance with these services is that the rendering is way off -- h elements not showing up as headers, elements missing randomly, source code incorrectly rendered in 10 different ways. Some are better than others, but generally they are disappointing. (Yet they expect you to pay a subscription fee.) If this is an actively maintained project that welcomes contribution, I could test it out with various articles and report/fix issues. Although I wonder how much work there will be for handling edge cases of all the websites out there.
1) convert html to markdown
This is what my library specifically addresses, and I believe it handles this task robustly. There was a lot of testing involved. For example, I used the CommonCrawl Dataset to automatically catch edge cases.
2) Identify article content
This is the more challenging aspect. You need to identify and extract the main content while removing peripheral elements (navigation bars, sidebars, ads, etc.)
For example, the top of the markdown document will have lots of links from the navbar otherwise.
Mozilla's "Readability" project (and its various ports) is the most used solution in this space. However, it relies on heuristic rules that need adjustments to work on every website.
---
The html-to-markdown project in combination with some heuristic would be great match! There is actually a comment below [1] about this topic. Feel free to contact me if you start this project, would be happy to help!
[1] https://news.ycombinator.com/item?id=42094012
[0]: https://github.com/dleeftink/plainmark
Your idea of comparing multiple pages would be a great approach. It would be amazing if you build something like this! This would enable so many more use cases... For example a better “send to kindle” (see other comment from rty32 [1]).
[1] https://news.ycombinator.com/item?id=42093964
You just fetch a URL like `https://r.jina.ai/https://www.asimov.press/p/mitochondria`, and get a markdown document for the "inner" URL.
I've actually used this and it's not perfect, there are websites (mostly those behind Cloudflare and other such proxies) that it can't handle, but it does 90% of the job, and is an one-liner in most languages with a decent HTTP requests library.
I also provide a REST API [1] that you can use for free (within limits). However you have get an API Key by registering with Github (see reason below).
---
The demo was previously hosted on Vercel. Someone misused the demo and send ~5 million requests per day. And would not stop — which quickly brought me over the bandwidth limits of Vercel. And bandwidth is really really expensive!
So that is the reason for requiring API Keys and hosting it on a VPS… Lessons learned!
[1] https://html-to-markdown.com/api
I contacted Vercel's Support to block that specific IP address but unfortunately they weren't helpful.
- Moved everything to a VPS - way better value for money. Extra TB of traffic only costs €1-10 with Hetzner/DigitalOcean compared to 400€ with Vercel's old pricing.
- Put Cloudflare in front - gives me an extra layer of control (if I ever need it)
- Built a proper REST API - now there's an official way to use the converter programmatically
- Made email registration mandatory for API keys - lets me reach out before having to block anyone
That other server was probably running a scraper and then converting the html-websites to markdown. After about 2 weeks they noticed that I was just returning garbage and it stopped :)
I've had good success with Cloudflare's free-tier features for rate limiting. If you haven't tried it, it only takes a couple minutes to enable and should be pretty set-and-forget for your API.
People will also want to note that it's LLM-powered which has pros and cons. One pro being that you can download and run their model yourself for non commercial use cases: https://huggingface.co/jinaai/reader-lm-1.5b
http://www.cantoni.org/2019/01/27/converting-html-markdown-u...
If you also want to grab an accurate screenshot with the markdown of a webpage you can get both with Urlbox.
We have a couple of free tools that use this feature:
https://screenshotof.com https://url2text.com
* https://github.com/vsch/flexmark-java/tree/master/flexmark-h... * https://github.com/vsch/flexmark-java
are you using a separate library for that or did I miss something in this?
But I wrote logic to handle that. It probably needs to be adapted at some point, but works surprisingly well. Have a look at the testdata files ("code.in.html" and "code.out.md" files [1]).
Feel free to give it a try & let me know if you notice any edge cases!
[1] https://github.com/JohannesKaufmann/html-to-markdown/blob/ma...