Aerostack
edit

text-markdown-to-html Edge Function — Content

Content

Converts Markdown text to HTML with optional sanitization. Supports all common Markdown syntax including headings, bold, italic, code blocks, lists, links, images, and blockquotes.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function text-markdown-to-html Converts Markdown text to HTML with optional sanitization. Supports all common Markdown syntax including headings, bold, italic, code blocks, lists, links, images, and blockquotes.. 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-markdown-to-html
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-markdown-to-html",
  args: {
    "markdown": "example_markdown",
    "sanitize": true
  }
})

text-markdown-to-html — Convert Markdown to HTML

Converts Markdown text to safe HTML. Supports all common Markdown syntax and optionally strips script tags and event handlers to prevent XSS.


API

POST /api/text-markdown-to-html

Request body

Field Type Required Default Description
markdown string The Markdown text to convert
sanitize boolean true Strip script tags and event handlers from output

Success response (200)

{
  "success": true,
  "data": {
    "html": "<h1>Hello World</h1>\n<p>This is a <strong>bold</strong> paragraph.</p>"
  }
}

Error responses

Code HTTP When
INVALID_INPUT 400 Missing or invalid markdown field
INTERNAL_ERROR 500 Unexpected processing error

Usage

cURL
curl -X POST "$FUNCTION_URL/api/text-markdown-to-html" \
  -H "Content-Type: application/json" \
  -d '{"markdown": "# Hello\n\nThis is **bold** and *italic*."}'
TypeScript / JavaScript (HTTP)
const response = await fetch(`${FUNCTION_URL}/api/text-markdown-to-html`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    markdown: '# Hello\n\nThis is **bold** and *italic*.',
    sanitize: true,
  }),
});
const { data } = await response.json();
console.log(data.html);
// <h1>Hello</h1>
// <p>This is <strong>bold</strong> and <em>italic</em>.</p>
Direct import (Node / Bun / Deno)
import { markdownToHtml } from '@aerostack/functions/text-markdown-to-html';

const result = markdownToHtml({
  markdown: '## Section\n\nSome `code` here.',
  sanitize: true,
});
console.log(result.html);

Supported Syntax

Markdown HTML Output
# Heading <h1>, <h2>, ..., <h6>
**bold** / __bold__ <strong>
*italic* / _italic_ <em>
`code` <code>
```lang\ncode\n``` <pre><code class="language-lang">
[text](url) <a href="url">
![alt](url) <img src="url" alt="alt">
- item / * item / + item <ul><li>
1. item <ol><li>
> quote <blockquote>
--- / *** <hr>
Two trailing spaces + newline <br>

Use Cases

  • AI chat interfaces: Convert AI-generated Markdown responses to HTML before rendering in a web UI or mobile app.
  • CMS content pipelines: Transform Markdown articles stored in a database to HTML for display on a website.
  • Email generation: Convert Markdown-authored email templates to HTML for sending via transactional email services.
  • Documentation sites: Render README files and documentation pages stored as Markdown.

Notes

  • sanitize: true (default) removes <script> tags and all on* event handler attributes to prevent XSS attacks.
  • Set sanitize: false only when you fully trust the input source.
  • This is a pure regex-based implementation — no external parser libraries are used.
  • Very large Markdown documents (>1MB) may see some performance overhead.

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-markdown-to-html function do? +

text-markdown-to-html 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-markdown-to-html function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/text-markdown-to-html ``` It will be live on Cloudflare Workers in seconds.

What runtime does text-markdown-to-html use? +

text-markdown-to-html runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the text-markdown-to-html function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.