text-html-to-markdown Edge Function — Content
ContentConverts HTML to Markdown text. Handles headings, bold, italic, links, code, lists, blockquotes, and horizontal rules. Strips all other HTML tags while preserving text content.
Edge function text-html-to-markdown Converts HTML to Markdown text. Handles headings, bold, italic, links, code, lists, blockquotes, and horizontal rules. Strips all other HTML tags while preserving text content.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.
npx aerostack add navin/text-html-to-markdown Use with AI Assistants
MCPConnect Claude, Cursor, or any MCP-compatible client — then call this function by slug
① Add MCP Server
Add this once — access all Aerostack functions from your AI tool.
{
"mcpServers": {
"aerostack": {
"url": "https://mcp.aerostack.dev",
"type": "http"
}
}
} ② Call this function
Ask your AI to use the call_function tool with this slug:
call_function({
slug: "text-html-to-markdown",
args: {
"html": "example_html",
"preserveLinks": true
}
}) text-html-to-markdown — Convert HTML to Markdown
Converts HTML content to clean Markdown text. Strips unknown tags while preserving headings, bold, italic, links, code, lists, and blockquotes.
API
POST /api/text-html-to-markdown
Request body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
html |
string | ✅ | — | The HTML string to convert |
preserveLinks |
boolean | ❌ | true |
Convert <a href> to [text](url) syntax, or strip to plain text |
Success response (200)
{
"success": true,
"data": {
"markdown": "# Hello World\n\nThis is **bold** and *italic*.",
"charCount": 44
}
}
Error responses
| Code | HTTP | When |
|---|---|---|
INVALID_INPUT |
400 | Missing or invalid html field |
INTERNAL_ERROR |
500 | Unexpected processing error |
Usage
cURL
curl -X POST "$FUNCTION_URL/api/text-html-to-markdown" \
-H "Content-Type: application/json" \
-d '{"html": "<h1>Hello</h1><p>This is <strong>bold</strong>.</p>"}'
TypeScript / JavaScript (HTTP)
const response = await fetch(`${FUNCTION_URL}/api/text-html-to-markdown`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
html: '<h1>Hello</h1><p>This is <strong>bold</strong>.</p>',
preserveLinks: true,
}),
});
const { data } = await response.json();
console.log(data.markdown);
// # Hello
//
// This is **bold**.
console.log(data.charCount); // 26
Direct import (Node / Bun / Deno)
import { htmlToMarkdown } from '@aerostack/functions/text-html-to-markdown';
const result = htmlToMarkdown({
html: '<ul><li>Item one</li><li>Item two</li></ul>',
preserveLinks: true,
});
console.log(result.markdown);
// - Item one
// - Item two
Use Cases
- Web scraping pipelines: Convert scraped HTML pages to Markdown before inserting into LLM prompts or RAG pipelines.
- CMS content migration: Convert legacy HTML articles to Markdown for storage in headless CMS systems or Git-based content repos.
- Document editing: Transform pasted HTML content into clean Markdown for storage in a Markdown-first editor.
- AI context preparation: Extract readable text from email HTML or rich-text content before passing to an AI model.
Notes
- Multiple blank lines (3+) are collapsed to a maximum of 2 to produce clean output.
- HTML entities (
&,<,", etc.) are decoded in the output. - HTML comments are stripped entirely.
- Unrecognized tags (e.g.
<div>,<span>,<table>) are removed but their text content is preserved.
Metadata
Tags
Publisher
@navin verified
Build and publish your own functions
Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.
More Content Functions
Browse Content Functions →text-extract-emails
by @navin
Extracts all valid email addresses from free-form text using an RFC 5321 compliant pattern. Supports deduplication and preserves order of first appearance.
text-markdown-to-html
by @navin
Converts Markdown text to HTML with optional sanitization. Supports all common Markdown syntax including headings, bold, italic, code blocks, lists, links, images, and blockquotes.
text-keyword-highlight
by @navin
Highlights keyword occurrences in text by wrapping them in configurable HTML tags. Handles case-insensitive matching, longest-match-first for overlapping keywords, and HTML entity escaping.
text-sanitize-html
by @navin
Sanitizes HTML by removing dangerous tags and attributes. Always strips script, style, iframe, form elements, and all event handlers. Keeps only whitelisted tags with whitelisted attributes.
text-slug-generate
by @navin
Generates a URL-safe slug from any string. Handles Unicode, accents, and special characters. Zero dependencies.
text-to-camel-case
by @navin
Converts a space-separated, snake_case, kebab-case, or PascalCase string to camelCase. Zero dependencies.
Frequently asked questions
What does the text-html-to-markdown function do? +
text-html-to-markdown is a serverless edge function for content automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.
How do I deploy the text-html-to-markdown function? +
Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/text-html-to-markdown ``` It will be live on Cloudflare Workers in seconds.
What runtime does text-html-to-markdown use? +
text-html-to-markdown runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.
Can I customise the text-html-to-markdown function? +
Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.