# Inline HTML and Markdown to Clean Markdown (`plainkitbin/markdown-convert`) Actor

Turn HTML snippets or Markdown text you supply into clean, normalized Markdown for LLM prompts and content pipelines. Keeps headings, paragraphs, quotes, code blocks, safe links and flat lists, drops scripts and styles, and adds SHA-256 hashes of source and output. Does not fetch web pages.

- **URL**: https://apify.com/plainkitbin/markdown-convert.md
- **Developed by:** [PlainKit bin](https://apify.com/plainkitbin) (community)
- **Categories:** Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.67 / 1,000 markdown document converteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## Inline HTML and Markdown to Clean Markdown

### Introduction

Inline HTML and Markdown to Clean Markdown converts inline HTML snippets or raw Markdown documents into normalized, clean Markdown with SHA-256 integrity hashes for both source and output. Designed for prompt preparation and content pipelines, this Actor operates purely on submitted text payloads without making external network calls or opening disk files. For format=html only, it cleans script, style, and noscript elements, standardizes line endings to LF, and formats headings and paragraphs cleanly; "clean" promises no transformations beyond the exact rules detailed in the "What is converted" section below. E-mail addresses and phone numbers in the content and names are automatically replaced with placeholders in markdown and document_name. The sha256.source digest covers the original raw input document content, while sha256.markdown covers the scrubbed output Markdown text.

### What is converted

Conversion behavior depends strictly on the input format declaration:

#### For format=html

- **Kept elements**:
  - Headings: `<h1>` through `<h6>` tags become standard `# ` through `###### ` Markdown headers.
  - Paragraphs: `<p>` blocks are preserved and separated by clean blank lines.
  - Blockquotes: `<blockquote>` tags become `> ` prefixed Markdown quotes.
  - Code blocks: `<pre>` elements are converted to fenced code blocks (` ``` `).
  - Safe links: `<a>` tags with `href` targets using `http`, `https`, or `mailto` schemes, or having no scheme (relative paths), are kept as standard `[link text](url)` links.
  - Flat bullet items: `<li>` items within `<ul>` or `<ol>` are converted to flat `- ` bullet items.
- **Dropped elements and limitations**:
  - Script, style, and noscript: Elements inside `<script>`, `<style>`, and `<noscript>` tags are removed completely.
  - Bold, italic, and inline code markup: Formatting tags (`<b>`, `<strong>`, `<i>`, `<em>`, `<code>`) are dropped; only the inner plain text is retained.
  - Images and alt text: `<img>` tags and their `alt` attributes are completely dropped and produce no output text.
  - List nesting: Nested lists are flattened into top-level bullet points; nesting indentations and hierarchy are dropped.
  - Table structure: Table rows (`<tr>`) with cells (`<td>`, `<th>`) are emitted as pipe-separated text (`cell1 | cell2`) without Markdown header separator rows, so rows are not a Markdown table.
  - Unsafe link targets: Any `href` scheme other than `http`, `https`, or `mailto` (such as `javascript:`, `data:`, or disguised schemes with whitespace or control characters) is dropped, keeping only the link text.

#### For format=markdown

- **Preserved content**:
  - Headings, paragraphs, fenced code blocks, and blockquotes are preserved.
  - Indented code blocks: Leading 4-space indentation is preserved.
  - Raw HTML and links: Raw HTML markup (including `<script>`, `<style>`, and raw `<a href="...">` links) inside Markdown text is passed through verbatim and not cleaned or stripped.

#### Use cases

- **LLM prompt preparation**: Clean and normalize messy HTML snippets or unstructured Markdown notes before feeding them to AI models.
- **Content pipeline normalization**: Enforce consistent blank-line spacing and clean block prefixes across diverse multi-source text inputs.
- **Deduplication indexing**: Use the deterministic SHA-256 hashes of input source and converted clean Markdown to index and deduplicate text items downstream.

### Tutorial

#### Step-by-step guide

1. Prepare a JSON payload with a `documents` array containing up to 1,000 document objects with `name`, `format` (`html` or `markdown`), and `content`.
2. Execute the Actor on Apify platform via web UI or API call.
3. The Actor processes each document in memory, converting markup tags into canonical Markdown and computing content hashes.
4. Retrieve the transformed dataset containing clean Markdown, block counts, and source/markdown SHA-256 hashes.

### Pricing

The Actor is priced per converted document using Pay-Per-Event under the **`markdown_conversion_document`** event. With the container document limit capped at 1,000 documents per execution, the largest bill per run is $1.00 for FREE tier, $0.90 for BRONZE tier, $0.80 for SILVER tier, $0.667 for GOLD tier, $0.667 for PLATINUM tier, and $0.667 for DIAMOND tier.

| Pricing tier | Price per event | Largest bill per run (1,000 docs) |
| --- | ---: | ---: |
| FREE | $0.001 | $1.00 |
| BRONZE | $0.0009 | $0.90 |
| SILVER | $0.0008 | $0.80 |
| GOLD | $0.000667 | $0.667 |
| PLATINUM | $0.000667 | $0.667 |
| DIAMOND | $0.000667 | $0.667 |

#### Charge contract

Each row is pushed first and charged right after a successful push; a refused charge stops work and that row stays delivered and uncharged; a reached limit stops work after that row was charged; failed items are neither pushed nor charged. A document that cannot be converted is skipped with a reason code, logged by its index and counted in the status message; it is neither pushed nor charged, and the run still succeeds. Only an input structure or size violation fails the whole run. Rows already in the dataset of a restarted run (matched by the pair of input_index and source sha256) are skipped and not charged again; if the dataset of a restarted run cannot be read, the run fails with DATASET_READ_FAILED before any new row or charge.

#### Operational limits

- Accepts 1 to 1,000 documents per execution.
- Document names must be 1 to 128 characters and contain no path separators (`/` or `\`).
- Each individual content string is limited to 1,000,000 UTF-8 bytes; total combined content must not exceed 5,000,000 bytes.
- Maximum 10,000 converted blocks and 2,000,000 output characters per document.
- Runs are bounded by a 3,600-second container timeout with a 30-second safety margin (RUN_TIME_BUDGET_REACHED).

### Input and output examples

#### Input example

```json
{
  "documents": [
    {
      "name": "welcome.html",
      "format": "html",
      "content": "<h1>Hello</h1><p>Welcome to Markdown.</p>"
    }
  ]
}
```

#### Output example

```json
{
  "input_index": 0,
  "markdown": "# Hello\n\nWelcome to Markdown.\n",
  "document_name": "welcome.html",
  "source_format": "html",
  "block_count": 2,
  "sha256": {
    "source": "075eddbe4d0c02440b8bebd0382e96c9490206d681815ddf8dad31433d0320bb",
    "markdown": "5e25c21b8a06ce280b85852de945ace459afb41385c20a77462aa3401f72d892"
  }
}
```

#### Output fields

| Field | Type | Description |
| --- | --- | --- |
| `input_index` | Integer | 0-based position of the document in the input list |
| `markdown` | String | Clean, normalized Markdown text representation |
| `document_name` | String | Identifier name provided in the input document object |
| `source_format` | String | Format declaration (`html` or `markdown`) |
| `block_count` | Integer | Total count of converted structural blocks |
| `sha256.source` | String | SHA-256 hash of the input document content |
| `sha256.markdown` | String | SHA-256 hash of the generated clean Markdown |

#### Content scrubbing and digest coverage

E-mail addresses and phone numbers detected in document content or names are replaced with `[email removed]` and `[phone removed]` placeholders in both `markdown` and `document_name` fields. The `sha256.source` digest represents the SHA-256 hash of the verbatim input document content prior to transformation, whereas `sha256.markdown` represents the SHA-256 hash of the delivered clean Markdown after contact scrubbing.

### Actor recommendations

Pair this Actor with:

- **Readable Article Extractor**: Refine raw article text into standardized Markdown blocks.
- **Web Page to Markdown Converter**: Convert full live web pages to Markdown before running lightweight inline cleanup.
- **CSV and JSON Integrity Parser**: Validate tabular data accompanying your textual documentation datasets.

### FAQ and support

#### Can I pass web URLs or local file paths?

No. Provide raw string content directly inside the `content` field.

#### Does it strip scripts and stylesheets from HTML?

Yes, for format=html only. Elements within `<script>`, `<style>`, and `<noscript>` tags in HTML input are removed before parsing text. In format=markdown, raw HTML elements are passed through untouched.

#### Does it deduplicate items automatically?

No. The Actor produces SHA-256 digests for each document, allowing you to filter duplicates downstream in your own pipeline.

#### Support and inquiries

For questions, feedback, or issues, submit a ticket in the Apify Console.

# Actor input Schema

## `documents` (type: `array`):

Required: provide 1 to 1000 inline text documents. Each item needs a non-empty name (up to 128 characters, without path separators), a format of html or markdown, and non-empty content. Each content is limited to 1,000,000 UTF-8 bytes and all contents together to 5,000,000 bytes.

## Actor input object example

```json
{
  "documents": [
    {
      "name": "welcome.html",
      "format": "html",
      "content": "<h1>Hello</h1><p>Welcome to Markdown.</p>"
    }
  ]
}
```

# Actor output Schema

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

Dataset items produced by this run.

# 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 = {
    "documents": [
        {
            "name": "welcome.html",
            "format": "html",
            "content": "<h1>Hello</h1><p>Welcome to Markdown.</p>"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("plainkitbin/markdown-convert").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 = { "documents": [{
            "name": "welcome.html",
            "format": "html",
            "content": "<h1>Hello</h1><p>Welcome to Markdown.</p>",
        }] }

# Run the Actor and wait for it to finish
run = client.actor("plainkitbin/markdown-convert").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 '{
  "documents": [
    {
      "name": "welcome.html",
      "format": "html",
      "content": "<h1>Hello</h1><p>Welcome to Markdown.</p>"
    }
  ]
}' |
apify call plainkitbin/markdown-convert --silent --output-dataset

```

## MCP server setup

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

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/Go3gWNnRlazFAezcl/builds/bAfvKXQKE1qtcenS7/openapi.json
