text-markdown-to-html Edge Function — Content
ContentConverts Markdown text to HTML with optional sanitization. Supports all common Markdown syntax including headings, bold, italic, code blocks, lists, links, images, and blockquotes.
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.
npx aerostack add navin/text-markdown-to-html 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-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"> |
 |
<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 allon*event handler attributes to prevent XSS attacks.- Set
sanitize: falseonly 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
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-html-to-markdown
by @navin
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.
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-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.