Need to convert Markdown to HTML? This guide covers everything you need to know about Markdown conversion via API, including syntax support, extensions, and security considerations.
What is Markdown?
Markdown is a lightweight markup language that uses plain text formatting syntax. It's designed to be converted to HTML and is widely used for documentation, README files, blog posts, and content management systems.
Example: "# Hello World" becomes "<h1>Hello World</h1>"
Supported Syntax
Common Markdown elements:
- Headers: # H1, ## H2, ### H3
- Emphasis: *italic*, **bold**, ***both***
- Lists: - unordered, 1. ordered
- Links: [text](url)
- Code: `inline` and ```blocks```
Using the Markdown to HTML API
TinyFn provides a simple endpoint to convert Markdown:
POST https://api.tinyfn.io/v1/text/markdown-to-html
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"markdown": "# Hello World\n\nThis is **bold** text.",
"gfm": true
}
{
"html": "<h1>Hello World</h1>\n<p>This is <strong>bold</strong> text.</p>",
"toc": [{"level": 1, "text": "Hello World", "id": "hello-world"}]
}
Parameters
| Parameter | Type | Description |
|---|---|---|
markdown |
string | The Markdown content to convert (required) |
gfm |
boolean | Enable GitHub Flavored Markdown (default: true) |
sanitize |
boolean | Sanitize HTML in output (default: true) |
generate_toc |
boolean | Generate table of contents (default: false) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/text/markdown-to-html',
{
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
markdown: '# Hello World\n\nThis is **bold** text.',
gfm: true
})
}
);
const result = await response.json();
console.log(result.html);
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/text/markdown-to-html',
headers={'X-API-Key': 'your-api-key'},
json={'markdown': '# Hello World\n\nThis is **bold** text.'}
)
result = response.json()
print(result['html'])
cURL
curl -X POST "https://api.tinyfn.io/v1/text/markdown-to-html" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"markdown": "# Hello World\n\nThis is **bold** text."}'
Common Use Cases
- Blog Platforms: Convert Markdown posts to HTML
- Documentation: Render docs written in Markdown
- CMS Integration: Support Markdown in content editors
- README Rendering: Display README files on websites
- Comment Systems: Allow Markdown formatting in comments
Best Practices
- Always sanitize: Enable sanitization for user-generated content
- Use GFM: GitHub Flavored Markdown is the de facto standard
- Cache results: Cache HTML output for static content
- Handle errors: Invalid Markdown should fail gracefully
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-text": {
"url": "https://api.tinyfn.io/mcp/text/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all text analysis tools available via MCP in our Text Analysis MCP Tools for AI Agents guide.
Try the Markdown to HTML API
Get your free API key and start converting Markdown in seconds.
Get Free API Key