Aerostack
edit

text-html-to-markdown Edge Function — Content

Content

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.

navin @navin verified
Updated Mar 12, 2026
GitHub

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.

terminal — aerostack cli
$ npx aerostack add navin/text-html-to-markdown
smart_toy

Use with AI Assistants

MCP

Connect 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.

claude_desktop_config.json
{
  "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
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 (&amp;, &lt;, &quot;, 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

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

text
deployed_code

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 →

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.