Dev.to AI 🤖 Ai 👁 0 📖 1 min read

Turn any web page or PDF into clean Markdown for your RAG pipeline

Feeding raw HTML to an LLM wastes tokens on menus, cookie banners and footers, and it loses the structure that makes chunking work. Markdown keeps headings, lists, tables and links, and drops the noise. What a

Feeding raw HTML to an LLM wastes tokens on menus, cookie banners and footers, and it loses the structure that makes chunking work. Markdown keeps headings, lists, tables and links, and drops the noise.

What a good converter should do

  • Remove navigation, ads, footers and scripts.
  • Keep headings (for chunking by section), lists, tables and links.
  • Add metadata: title, URL, language, word count.
  • Handle PDFs too, because half of the useful documents on the web are PDFs.
  • Be fast and cheap: no headless browser for static pages.

That's what Website to Markdown Converter for LLM & RAG does. For PDF-only jobs there's a dedicated PDF Text Extractor that works page by page.

From Python

from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("iscle/url-to-markdown-llm").call(run_input={
    "urls": ["https://docs.python.org/3/tutorial/classes.html"],
})
for page in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(page["title"])
    print(page["markdown"][:500])

Chunking by heading

import re

def chunks(md, max_chars=2000):
    parts = re.split(r"\n(?=#{1,3} )", md)
    buf = ""
    for p in parts:
        if len(buf) + len(p) > max_chars and buf:
            yield buf
            buf = ""
        buf += "\n" + p
    if buf:
        yield buf

Each chunk starts with its heading, which gives the embedding useful context.

Cost

Pay per page converted; errors and empty pages are free.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.