# HTML to Markdown Converter – Clean HTML & Datasets for LLMs (`gazidev/html-to-markdown-converter`) Actor

Convert HTML you already have to clean Markdown: pasted HTML, JSON documents, the html field of any scraper dataset, or HTML file URLs. Removes nav, footers and cookie banners, keeps tables and code, makes links absolute. Optional RAG chunks. No page fetching. $0.30 per 1,000 documents.

- **URL**: https://apify.com/gazidev/html-to-markdown-converter.md
- **Developed by:** [Cemal Atakli](https://apify.com/gazidev) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.30 / 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 Converter – Clean HTML & Datasets for LLMs

Convert **HTML you already have** to clean Markdown: pasted HTML, a JSON list of documents, the `html` field of any **scraper dataset**, or HTML files at a URL. The Actor removes navigation, headers, footers, sidebars and cookie banners. It keeps headings, lists, GFM tables and fenced code blocks, and makes relative links absolute. Optional RAG chunks with token counts.

**It does not crawl or fetch web pages.** That is the difference from our other Markdown listings (see below). Cost: **$0.30 per 1,000 HTML documents**.

### What this listing does that our others do not

| You have… | Use |
|---|---|
| **HTML already** (a string, a scraper dataset, an exported `.html` file) | **This Actor** – converts only, never visits the site |
| A list of URLs or a whole site to crawl | [Fast Website Content Crawler (website-to-markdown)](https://apify.com/gazidev/website-to-markdown) |
| One URL for an AI agent, as Markdown, text or HTML | [Web Fetch](https://apify.com/gazidev/web-fetch) |
| DOCX, PPTX, XLSX or PDF files | [Document to Markdown](https://apify.com/gazidev/document-to-markdown) |
| News or blog URLs, as structured article JSON | [Article Extractor](https://apify.com/gazidev/article-extractor) |
| A dataset to merge, dedupe or filter (not convert) | [Merge, Dedup & Transform Datasets](https://apify.com/gazidev/dataset-filter-transform) |

### What it does

- **Four input sources** (use one or several in the same run):
  - `html`: one HTML document or fragment, pasted.
  - `htmlDocuments`: a JSON array of HTML strings or `{id, html, url}` objects.
  - `datasetId`: any Apify dataset. Pick the HTML field (dot paths such as `response.body` work), the URL field, and fields to copy to the output.
  - `fileUrls`: direct links to HTML files (S3, GitHub raw, an Apify key-value store record). Max 10 MB per file. Private and internal network addresses are refused.
- **Boilerplate removal** (on by default): scripts, styles, forms, nav, header, footer, aside, cookie/consent banners, share bars, "related posts". The main block is found from `<main>`, `<article>` and common content containers, with a text-density fallback. Turn it off to convert the whole body.
- **Good Markdown**: headings, nested lists, GFM tables, fenced code with the language, blockquotes, bold/italic, links. Images optional.
- **Absolute links** from the item's own URL, a `<base href>`, or the `baseUrl` you give.
- **Metadata**: title, meta description, language, canonical URL, word count, estimated tokens, SHA-256 of the Markdown.
- **RAG chunks** (optional): `chunks[]` with `{index, headingPath, text, tokens}`, split on headings and paragraphs.
- **Fair charging**: empty HTML, JavaScript app shells with no text, missing fields and failed downloads are listed in the output but **not charged**.

### Use cases

- You scraped pages with a browser-based scraper and stored the rendered `html`: turn the whole dataset into Markdown for an LLM or vector database.
- Clean up HTML e-mails, CMS exports, help-centre dumps or saved `.html` files.
- An AI agent already holds HTML and needs compact Markdown (fewer tokens than raw HTML).
- Run it after a scraper with an integration: `datasetId` = `{{resource.defaultDatasetId}}`.

### Input example

```json
{
  "datasetId": "abc123XYZ",
  "htmlField": "html",
  "urlField": "url",
  "keepFields": ["title"],
  "mainContentOnly": true,
  "chunkSize": 800
}
```

With no input at all, the Actor converts a small built-in sample document so you can see the output format.

### Output example

```json
{
  "source": "input.html",
  "url": "https://example.com/blog/",
  "status": "converted",
  "title": "Release notes 2.4 | Example Blog",
  "description": "What changed in version 2.4: faster exports, a new CLI flag and two fixes.",
  "lang": "en",
  "markdown": "# Release notes 2.4\n\nVersion 2.4 makes **exports about 3x faster** and adds a `--dry-run` flag. Read the [export guide](https://example.com/docs/export) …\n\n| Rows | 2.3 | 2.4 |\n|---|---|---|\n| 10,000 | 4.1 s | 1.3 s |\n…",
  "wordCount": 85,
  "tokenCount": 140,
  "htmlChars": 1568,
  "markdownChars": 560,
  "error": null
}
```

`status` is `converted` (charged), `empty`, `jsShell` or `error` (not charged). A run summary is saved as `OUTPUT` in the key-value store.

### Pricing

Pay per event, you pay only for documents that were converted:

| Event | Price |
|---|---|
| HTML document converted (`page-converted`) | $0.0003 ($0.30 per 1,000) |
| Actor start | $0.00005 |

| Actor | Converts supplied HTML | Price per document |
|---|---|---|
| **This Actor** | yes (string, JSON, dataset, file URL) | $0.0003 |
| web.harvester/html-to-markdown | yes | $0.002 |
| Our website-to-markdown | no, fetches URLs | $0.0004 per page |

Your maximum charge per run is respected: the Actor stops cleanly when it is reached and says so in the status message and `OUTPUT`.

### Limits (honest)

- No JavaScript is run. If your HTML is an empty app shell (`<div id="root">`), save the HTML after rendering and convert that. Such documents are marked `jsShell` and free.
- Boilerplate removal is heuristic. On unusual layouts, turn off `mainContentOnly` or add `removeSelectors`.
- Token counts are an estimate (4 characters ≈ 1 token).
- Documents over 10 million characters (or files over 10 MB) are cut, and the row says so.
- File URLs must be public http(s) links; private, loopback and cloud-metadata addresses are refused.

### FAQ

**Does it visit the URLs in my dataset?** No. The `url` field is only used to make relative links absolute. Only `fileUrls` are downloaded, once each.

**Can I keep my scraper's other fields?** Yes, list them in `keepFields`; they appear under `sourceFields`.

**My HTML sits in a nested field.** Use a dot path, e.g. `response.body` or `data.0.html`.

### Use with AI agents / Apify MCP

Add this Actor to the [Apify MCP server](https://mcp.apify.com) (`gazidev/html-to-markdown-converter`). An agent can send `htmlDocuments: [{"html": "...", "url": "https://..."}]` and read `markdown` from the dataset. It is a cheap way to shrink HTML before it goes into a context window.

# Actor input Schema

## `html` (type: `string`):

Paste one HTML document or fragment. Leave empty if you use the other sources. With no input at all, a built-in sample document is converted.

## `htmlDocuments` (type: `array`):

A JSON array of HTML strings, or of objects like {"id": "a1", "html": "<p>...</p>", "url": "https://site.com/page"}. The url (or baseUrl) of each object is used to make its relative links absolute. Handy for API calls and AI agents.

## `datasetId` (type: `string`):

Convert an HTML field of every item in a dataset, e.g. the output of a scraper that saved page HTML. In an integration / webhook use {{resource.defaultDatasetId}}.

## `htmlField` (type: `string`):

Name of the field that holds the HTML in the dataset items. Dot paths work, e.g. response.body.

## `urlField` (type: `string`):

Field with the page URL, used as the base for relative links and copied to the output. Leave empty if there is none.

## `keepFields` (type: `array`):

Fields of the source item to copy to each output row (under sourceFields), e.g. title, category, scrapedAt.

## `fileUrls` (type: `array`):

Direct links to HTML files you host or exported (S3, GitHub raw, an Apify key-value store record, ...). Each file is downloaded once (max 10 MB). Private and internal network addresses are refused. To crawl live websites, use our Website to Markdown actor instead.

## `baseUrl` (type: `string`):

Used to make relative links and images absolute when a document has no URL of its own (e.g. https://example.com/blog/). A <base href> in the HTML wins.

## `mainContentOnly` (type: `boolean`):

Keep only the main content: drops navigation, headers, footers, sidebars, cookie banners, share bars and similar. Turn off to convert the whole body.

## `includeLinks` (type: `boolean`):

Write links as [text](url). Off = plain link text only (fewer tokens).

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

Write images as ![alt](url).

## `removeSelectors` (type: `string`):

Comma-separated CSS selectors removed before conversion, e.g. .ad-box, #comments, .author-bio.

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

If above 0, each row also gets chunks\[] split on headings and paragraphs, about this many tokens each (estimate: 4 characters = 1 token), with the heading path. Code blocks are not split. 0 = off.

## `maxItems` (type: `integer`):

Stop after this many documents (all sources together). Empty = no limit. Your maximum charge per run is also respected.

## Actor input object example

```json
{
  "html": "<!doctype html>\n<html lang=\"en\"><head><title>Release notes 2.4 | Example Blog</title>\n<meta name=\"description\" content=\"What changed in version 2.4: faster exports, a new CLI flag and two fixes.\">\n<script>window.dataLayer=[];</script><style>body{font-family:sans-serif}</style></head>\n<body>\n<div id=\"cookie-banner\" class=\"cookie-consent\">We use cookies. <button>Accept all</button></div>\n<header class=\"site-header\"><nav><a href=\"/\">Home</a> <a href=\"/blog/\">Blog</a> <a href=\"/pricing\">Pricing</a></nav></header>\n<main>\n<article>\n<h1>Release notes 2.4</h1>\n<p>Version 2.4 makes <strong>exports about 3x faster</strong> and adds a <code>--dry-run</code> flag.\nRead the <a href=\"../docs/export\">export guide</a> or the <a href=\"changelog#v2-4\">full changelog</a>.</p>\n<h2>What changed</h2>\n<ul><li>Faster CSV and JSON exports</li><li>New <code>--dry-run</code> flag<ul><li>prints the plan only</li></ul></li>\n<li>Two bug fixes</li></ul>\n<h2>Benchmarks</h2>\n<table><tr><th>Rows</th><th>2.3</th><th>2.4</th></tr><tr><td>10,000</td><td>4.1 s</td><td>1.3 s</td></tr>\n<tr><td>100,000</td><td>39 s</td><td>12 s</td></tr></table>\n<h2>Try it</h2>\n<pre><code class=\"language-bash\">pip install example-cli==2.4\nexample export --format csv --dry-run</code></pre>\n<blockquote>Tip: the old flags still work.</blockquote>\n<img src=\"/img/chart.png\" alt=\"Export speed chart\">\n</article>\n<aside class=\"sidebar\"><h3>Related posts</h3><a href=\"/blog/2-3\">Release notes 2.3</a></aside>\n</main>\n<footer><p>&copy; 2026 Example Inc. <a href=\"/privacy\">Privacy</a></p></footer>\n</body></html>",
  "htmlField": "html",
  "urlField": "url",
  "keepFields": [],
  "baseUrl": "https://example.com/blog/",
  "mainContentOnly": true,
  "includeLinks": true,
  "includeImages": false,
  "chunkSize": 0
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

## `markdown` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `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 = {
    "html": `<!doctype html>
<html lang="en"><head><title>Release notes 2.4 | Example Blog</title>
<meta name="description" content="What changed in version 2.4: faster exports, a new CLI flag and two fixes.">
<script>window.dataLayer=[];</script><style>body{font-family:sans-serif}</style></head>
<body>
<div id="cookie-banner" class="cookie-consent">We use cookies. <button>Accept all</button></div>
<header class="site-header"><nav><a href="/">Home</a> <a href="/blog/">Blog</a> <a href="/pricing">Pricing</a></nav></header>
<main>
<article>
<h1>Release notes 2.4</h1>
<p>Version 2.4 makes <strong>exports about 3x faster</strong> and adds a <code>--dry-run</code> flag.
Read the <a href="../docs/export">export guide</a> or the <a href="changelog#v2-4">full changelog</a>.</p>
<h2>What changed</h2>
<ul><li>Faster CSV and JSON exports</li><li>New <code>--dry-run</code> flag<ul><li>prints the plan only</li></ul></li>
<li>Two bug fixes</li></ul>
<h2>Benchmarks</h2>
<table><tr><th>Rows</th><th>2.3</th><th>2.4</th></tr><tr><td>10,000</td><td>4.1 s</td><td>1.3 s</td></tr>
<tr><td>100,000</td><td>39 s</td><td>12 s</td></tr></table>
<h2>Try it</h2>
<pre><code class="language-bash">pip install example-cli==2.4
example export --format csv --dry-run</code></pre>
<blockquote>Tip: the old flags still work.</blockquote>
<img src="/img/chart.png" alt="Export speed chart">
</article>
<aside class="sidebar"><h3>Related posts</h3><a href="/blog/2-3">Release notes 2.3</a></aside>
</main>
<footer><p>&copy; 2026 Example Inc. <a href="/privacy">Privacy</a></p></footer>
</body></html>`,
    "baseUrl": "https://example.com/blog/"
};

// Run the Actor and wait for it to finish
const run = await client.actor("gazidev/html-to-markdown-converter").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 = {
    "html": """<!doctype html>
<html lang=\"en\"><head><title>Release notes 2.4 | Example Blog</title>
<meta name=\"description\" content=\"What changed in version 2.4: faster exports, a new CLI flag and two fixes.\">
<script>window.dataLayer=[];</script><style>body{font-family:sans-serif}</style></head>
<body>
<div id=\"cookie-banner\" class=\"cookie-consent\">We use cookies. <button>Accept all</button></div>
<header class=\"site-header\"><nav><a href=\"/\">Home</a> <a href=\"/blog/\">Blog</a> <a href=\"/pricing\">Pricing</a></nav></header>
<main>
<article>
<h1>Release notes 2.4</h1>
<p>Version 2.4 makes <strong>exports about 3x faster</strong> and adds a <code>--dry-run</code> flag.
Read the <a href=\"../docs/export\">export guide</a> or the <a href=\"changelog#v2-4\">full changelog</a>.</p>
<h2>What changed</h2>
<ul><li>Faster CSV and JSON exports</li><li>New <code>--dry-run</code> flag<ul><li>prints the plan only</li></ul></li>
<li>Two bug fixes</li></ul>
<h2>Benchmarks</h2>
<table><tr><th>Rows</th><th>2.3</th><th>2.4</th></tr><tr><td>10,000</td><td>4.1 s</td><td>1.3 s</td></tr>
<tr><td>100,000</td><td>39 s</td><td>12 s</td></tr></table>
<h2>Try it</h2>
<pre><code class=\"language-bash\">pip install example-cli==2.4
example export --format csv --dry-run</code></pre>
<blockquote>Tip: the old flags still work.</blockquote>
<img src=\"/img/chart.png\" alt=\"Export speed chart\">
</article>
<aside class=\"sidebar\"><h3>Related posts</h3><a href=\"/blog/2-3\">Release notes 2.3</a></aside>
</main>
<footer><p>&copy; 2026 Example Inc. <a href=\"/privacy\">Privacy</a></p></footer>
</body></html>""",
    "baseUrl": "https://example.com/blog/",
}

# Run the Actor and wait for it to finish
run = client.actor("gazidev/html-to-markdown-converter").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 '{
  "html": "<!doctype html>\\n<html lang=\\"en\\"><head><title>Release notes 2.4 | Example Blog</title>\\n<meta name=\\"description\\" content=\\"What changed in version 2.4: faster exports, a new CLI flag and two fixes.\\">\\n<script>window.dataLayer=[];</script><style>body{font-family:sans-serif}</style></head>\\n<body>\\n<div id=\\"cookie-banner\\" class=\\"cookie-consent\\">We use cookies. <button>Accept all</button></div>\\n<header class=\\"site-header\\"><nav><a href=\\"/\\">Home</a> <a href=\\"/blog/\\">Blog</a> <a href=\\"/pricing\\">Pricing</a></nav></header>\\n<main>\\n<article>\\n<h1>Release notes 2.4</h1>\\n<p>Version 2.4 makes <strong>exports about 3x faster</strong> and adds a <code>--dry-run</code> flag.\\nRead the <a href=\\"../docs/export\\">export guide</a> or the <a href=\\"changelog#v2-4\\">full changelog</a>.</p>\\n<h2>What changed</h2>\\n<ul><li>Faster CSV and JSON exports</li><li>New <code>--dry-run</code> flag<ul><li>prints the plan only</li></ul></li>\\n<li>Two bug fixes</li></ul>\\n<h2>Benchmarks</h2>\\n<table><tr><th>Rows</th><th>2.3</th><th>2.4</th></tr><tr><td>10,000</td><td>4.1 s</td><td>1.3 s</td></tr>\\n<tr><td>100,000</td><td>39 s</td><td>12 s</td></tr></table>\\n<h2>Try it</h2>\\n<pre><code class=\\"language-bash\\">pip install example-cli==2.4\\nexample export --format csv --dry-run</code></pre>\\n<blockquote>Tip: the old flags still work.</blockquote>\\n<img src=\\"/img/chart.png\\" alt=\\"Export speed chart\\">\\n</article>\\n<aside class=\\"sidebar\\"><h3>Related posts</h3><a href=\\"/blog/2-3\\">Release notes 2.3</a></aside>\\n</main>\\n<footer><p>&copy; 2026 Example Inc. <a href=\\"/privacy\\">Privacy</a></p></footer>\\n</body></html>",
  "baseUrl": "https://example.com/blog/"
}' |
apify call gazidev/html-to-markdown-converter --silent --output-dataset

```

## MCP server setup

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

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/1QdqEcbzaQ3BsYmkw/builds/PyfrKgcSCnzBBvlDK/openapi.json
