BlogGuides
Website to Markdown for LLMs: why it cuts tokens and how to automate it
Why clean Markdown outperforms raw HTML in LLM prompts and RAG, what good HTML-to-Markdown conversion strips, and how to automate it via API or MCP.
Feeding raw HTML to an LLM wastes context tokens on <script> tags, SVG paths, cookie banners, and nested layout <div> wrappers. Converting a website to Markdown strips that boilerplate while keeping the hierarchy models actually rely on: headings, links, tables, and fenced code blocks.
Try it interactively on the free website to Markdown and HTML to Markdown tools, or read the URL to Markdown API overview.
#Why does Markdown work better than raw HTML or plain text?
Plain text (innerText) removes noise, but it also destroys structure: headings collapse into paragraphs, tables turn into unreadable columns, and code blocks lose language tags. Clean Markdown hits the sweet spot:
| Format | Preserves headings & tables | Strips nav & scripts | Token efficiency |
|---|---|---|---|
| Raw HTML | Yes (noisy) | No | Low (heavy tag overhead) |
| Plain text | No | Partially | High (but loses structure) |
| Clean Markdown | Yes | Yes | High |
Models trained on billions of lines of GitHub READMEs and technical docs parse # headings, | table | syntax, and ```ts fences natively.
#What should a good HTML-to-Markdown pipeline strip vs keep?
A reliable converter does more than run regex over tags:
- Extract main content first: drop
<nav>,<footer>,<aside>, cookie modals, and inline<script>/<style>blocks before converting. - Resolve relative URLs: turn
/docs/authintohttps://example.com/docs/authso agents can follow citations without guessing the origin. - Preserve tables and code blocks: keep language hints (
language-tsto```ts) and GFM pipe tables intact. - Fallback to browser rendering only when needed: fetch static HTML directly first, and render JavaScript only when the initial document is an empty app shell.
- Return metadata alongside Markdown: title, description, canonical URL, and status code help downstream RAG filters.
#How do you convert a URL to Markdown via API, CLI, or MCP?
#REST (POST /v1/scrape)
curl -X POST https://webcrawl.app/v1/scrape \
-H "Authorization: Bearer $WEBCRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://webcrawl.app/docs/scrape","formats":["markdown"]}'
#TypeScript (@webcrawl/client)
import { createClient } from "@webcrawl/client";
const client = createClient({ apiKey: process.env.WEBCRAWL_API_KEY });
const res = await client.scrape({ url: "https://example.com/docs" });
console.log(res.markdown);
#CLI and MCP
npx webcrawl scrape https://example.com/docs
Inside Claude Code, Cursor, or Codex with Webcrawl MCP connected, the agent calls web_read directly and receives Markdown without any shell script.
#When should a site serve .md mirrors directly?
If you publish documentation or marketing pages, you do not have to force every agent to scrape HTML at all. Serving a .md mirror (like https://webcrawl.app/docs/scrape.md) with <link rel="alternate" type="text/markdown"> lets agents fetch clean Markdown in one GET request. See what is llms.txt and AEO for developer docs.
#FAQ
#Does converting HTML to Markdown break code examples?
Not when the parser reads <pre><code class="language-..."> elements before collapsing whitespace. Good converters keep indentation and attach the language identifier to the fenced block.
#How do you handle pages that render content with JavaScript?
Start with an HTTP fetch for speed; if the response is a client-rendered shell with minimal text, fall back to a headless browser render before running main-content extraction.
#Is there a free way to test website-to-Markdown conversion?
Yes. Use the website to Markdown tool in your browser with no account, or sign up for 1,000 free monthly API credits on webcrawl.app.