# HTML to Markdown for LLM & RAG — Clean Page Content + Chunks (`openregistry/html-to-markdown`) Actor

Turn web pages or raw HTML into clean Markdown for LLMs, RAG and AI agents: main content only (no menus, ads, footers), absolute links, GFM tables, code blocks with language, title and metadata, optional chunks. Respects robots.txt. Pay per page.

- **URL**: https://apify.com/openregistry/html-to-markdown.md
- **Developed by:** [Mahé Perrin](https://apify.com/openregistry) (community)
- **Categories:** AI, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 page converteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## HTML to Markdown for LLM & RAG — Clean Page Content + Chunks

Feed it web page URLs (or your own HTML) and get **clean Markdown ready for an LLM, a RAG index or an AI agent**: only the main content, no menus, cookie banners, sidebars or footers, with absolute links, proper tables and fenced code blocks. Optional chunking on paragraph boundaries, each chunk tagged with its section heading.

Why Markdown: it keeps the structure (headings, lists, tables, code) that models rely on, at a fraction of the tokens of raw HTML.

### Features

- **Main content extraction** with a Readability-style algorithm (the one behind Firefox Reader View); falls back to the whole body when the page has no article.
- **GitHub-flavored Markdown**: `#` headings, `-` lists, pipe tables, fenced code blocks that keep their language (` ```python `).
- **Absolute links**, inline or as numbered references, or dropped entirely to save tokens; link tooltips and empty image links removed.
- **Metadata**: title, meta description, language, final URL after redirects, HTTP status, word count, list of links.
- **Chunks for embeddings**: size in characters, optional overlap, never cuts inside a code block.
- **Your own HTML**: paste HTML strings (from an email, a CMS export, another scraper) with an optional base URL for relative links.
- Correct character sets (UTF-8, ISO-8859-1, Windows-1252...) from the HTTP header or the page's `<meta charset>`.

### What it is for

- Building a **knowledge base / RAG index** from documentation, help centers or blog posts.
- Giving an **AI agent** readable page content through the API, Make, Zapier or n8n.
- **Summarizing or translating** articles with an LLM without paying for HTML tokens.
- Archiving pages as plain-text Markdown in Git, Notion or Obsidian.
- Combine it with a sitemap extractor to convert a whole documentation site.

### Input example

```json
{
  "startUrls": ["https://en.wikipedia.org/wiki/Markdown"],
  "htmlItems": [{ "html": "<h1>Notes</h1><p>Hello <a href='/a'>link</a></p>", "url": "https://example.com/", "name": "notes" }],
  "extractionMode": "main",
  "linkStyle": "inline",
  "chunkSize": 2000,
  "chunkOverlap": 200
}
```

- `startUrls` — pages to fetch; `htmlItems` — HTML you provide (nothing fetched).
- `extractionMode` — `main` (default) or `full`.
- `linkStyle` — `inline`, `referenced` or `text`; `includeImages`, `includeLinkList`.
- `chunkSize`, `chunkOverlap` — chunking (0 = off).
- `maxConcurrency`, `maxPageSizeMb`, `maxResults` — limits; `maxResults` caps the cost.

### Output example

One dataset row per page:

```json
{
  "index": 1,
  "url": "https://en.wikipedia.org/wiki/Markdown",
  "finalUrl": "https://en.wikipedia.org/wiki/Markdown",
  "statusCode": 200,
  "title": "Markdown",
  "description": null,
  "language": "en",
  "extraction": "main",
  "wordCount": 5053,
  "markdown": "From Wikipedia, the free encyclopedia\n\n**Markdown** is a lightweight markup language for creating formatted text...",
  "links": [{ "text": "lightweight markup language", "url": "https://en.wikipedia.org/wiki/Lightweight_markup_language" }],
  "chunks": [{ "index": 0, "heading": "History", "text": "## History\n\n...", "chars": 1987 }],
  "error": null
}
```

### Good to know

- **Honest fetching**: plain HTTP requests with the Actor's own User-Agent (`OpenRegistry-HtmlToMarkdown`), `robots.txt` checked before every request and after each redirect, requests to the same site spaced out. No headless browser, no imitation of a real browser, no proxies, no CAPTCHA solving. Pages that forbid automated access, need a login, or only render with JavaScript come back as an error row and are **not charged**.
- Only use it on content you are allowed to process; respect the site's terms and copyright.
- Main-content detection is heuristic: on unusual layouts (home pages, product grids) try `extractionMode: "full"`.

### Pricing

**$0.001 per page** ($1 per 1,000 pages), chunks included. Failed pages are free. Set a maximum charge per run in the Apify console and the Actor stops cleanly when it is reached.

# Actor input Schema

## `startUrls` (type: `array`):

Public web pages to fetch and convert, one per line. Pages that need JavaScript to show their text, or that block automated clients, return an error row (not charged).

## `htmlItems` (type: `array`):

Optional. Strings of HTML, or objects { "html": "...", "url": "https://base-for-relative-links/", "name": "my-doc" }. Nothing is fetched for these.

## `extractionMode` (type: `string`):

Main content uses a Readability-style algorithm and falls back to the whole body when no article is detected.

## `linkStyle` (type: `string`):

Links are made absolute.

## `includeImages` (type: `boolean`):

Adds ![alt](url) lines. Off by default to save tokens.

## `includeLinkList` (type: `boolean`):

Adds a "links" array (text + absolute URL) found in the kept content.

## `chunkSize` (type: `integer`):

Splits the Markdown into chunks of at most this many characters, on paragraph boundaries, never inside a code block. Each chunk keeps its section heading. 1,500 to 4,000 suits most embedding models.

## `chunkOverlap` (type: `integer`):

Repeats the last paragraphs of a chunk at the start of the next one, up to this many characters (at most half the chunk size).

## `maxConcurrency` (type: `integer`):

Different websites are fetched in parallel; requests to the same website are always spaced out.

## `maxPageSizeMb` (type: `integer`):

Larger pages are skipped (not charged).

## `maxResults` (type: `integer`):

The run stops once this many pages are converted, so you control the cost.

## Actor input object example

```json
{
  "startUrls": [
    "https://en.wikipedia.org/wiki/Markdown"
  ],
  "extractionMode": "main",
  "linkStyle": "inline",
  "includeImages": false,
  "includeLinkList": true,
  "chunkSize": 0,
  "chunkOverlap": 0,
  "maxConcurrency": 5,
  "maxPageSizeMb": 10,
  "maxResults": 10000
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "startUrls": [
        "https://en.wikipedia.org/wiki/Markdown"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("openregistry/html-to-markdown").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "startUrls": ["https://en.wikipedia.org/wiki/Markdown"] }

# Run the Actor and wait for it to finish
run = client.actor("openregistry/html-to-markdown").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "startUrls": [
    "https://en.wikipedia.org/wiki/Markdown"
  ]
}' |
apify call openregistry/html-to-markdown --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,openregistry/html-to-markdown"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/YiyTeehA4qeNSUkWE/builds/ZZoQF1cQMXYCAj3VG/openapi.json
