HTML to Markdown in more depth
Raw HTML carries a lot that a reader never sees: class attributes, inline styles, tracking scripts, nested <div> wrappers. For a language model every one of those characters is a token, and for a search index it is noise. Plain text goes too far the other way, flattening headings and tables so structure is lost.
Markdown sits in between. A heading is still a heading (## Pricing), a list is still a list, a link keeps its URL, and a table keeps its rows. That structure is exactly what document chunking uses to split content at sensible boundaries.
How conversion works
- Parse the HTML into a DOM tree.
- Optionally reduce it to the main content first; see main content extraction.
- Walk the tree and map each element to Markdown syntax.
- Resolve relative links and image paths against the page URL.
- Clean up whitespace and escape characters that Markdown would misread.
| HTML | Markdown |
|---|---|
<h2>Setup</h2> | ## Setup |
<strong>, <em> | **bold**, *italic* |
<a href="/docs">Docs</a> | [Docs](https://site.com/docs) |
<ul><li> | - item |
<pre><code> | fenced code block |
<table> | pipe table (GitHub-flavoured Markdown) |
Example
The same content as rendered HTML is typically several times longer once wrappers and attributes are counted. You can compare on your own pages with the HTML to markdown tool.
Common pitfalls
- Complex tables. Merged cells (
rowspan,colspan) and nested tables have no Markdown equivalent and come out flattened or garbled. - Layout tables and divs used for visual grids can turn into meaningless runs of text.
- Converting the chrome. Without content extraction, every page starts with the same menu and ends with the same footer.
- Relative links left unresolved, which break once the text leaves the site.
- Images. Alt text survives; the information in a chart or diagram does not.
How SarvCrawl handles it
Markdown is the default output of every scrape and crawl. Pages are rendered in a real browser first, so client-side content is included, and main-content extraction strips nav, footer, aside, script and style before conversion. The same pipeline parses uploaded PDFs, Office files, EPUBs and images into markdown, with OCR for scanned PDFs and a conversion audit that scores each conversion. The markdown is then chunked and embedded into a knowledge base. For one page at a time, use the free HTML to markdown or PDF to markdown tools.
Frequently asked questions
Why convert HTML to Markdown for LLMs?
Markdown keeps headings, lists, tables and links but drops tags and attributes, so the same content uses far fewer tokens and is easier for the model to follow.
Does Markdown keep tables?
Simple tables, yes, as pipe tables. Tables with merged or nested cells cannot be represented exactly and usually need simplifying.
Should I strip navigation before converting?
Usually. Navigation and footers repeat on every page and add noise to search and model context. Keep them only when the navigation itself is the content you need.