Markup¶
2 endpoints for converting between Markdown, HTML, and plain text.
| Method | Endpoint | Purpose |
|---|---|---|
POST |
/v1/convert/markup |
Convert between Markdown, HTML, and plain text |
GET |
/v1/convert/markup |
Stream a converted file from a URL source |
Python SDK Examples¶
Markdown to HTML¶
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
result = cv.markup(
from_format="markdown",
to_format="html",
content="# Hello\n\nThis is **bold** and *italic* text.",
gfm=True,
)
print(result["result"])
# <h1>Hello</h1>
# <p>This is <strong>bold</strong> and <em>italic</em> text.</p>
Markdown to HTML with sanitization¶
Enable sanitize=True to strip unsafe tags and attributes — useful when rendering user-supplied Markdown in a browser.
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
untrusted_md = "# Safe heading\n\n<script>alert('xss')</script>\n\nNormal paragraph."
result = cv.markup(
from_format="markdown",
to_format="html",
content=untrusted_md,
sanitize=True,
)
print(result["result"])
# <h1>Safe heading</h1>
# <p>Normal paragraph.</p>
HTML to Markdown¶
Useful for extracting clean Markdown from a CMS or scraped page.
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
html = "<h2>Getting Started</h2><p>Install with <code>pip install toolkitapi</code>.</p>"
result = cv.markup(
from_format="html",
to_format="markdown",
content=html,
preserve_links=True,
preserve_tables=True,
)
print(result["result"])
# ## Getting Started
#
# Install with `pip install toolkitapi`.
HTML to plain text¶
Strip all markup and return readable plain text — handy for search indexing or email fallbacks.
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
result = cv.markup(
from_format="html",
to_format="text",
content="<h1>Report</h1><p>Q3 revenue was <strong>$4.2M</strong>, up 12%.</p>",
)
print(result["result"])
# Report
# Q3 revenue was $4.2M, up 12%.
Convert a remote Markdown file and download as HTML¶
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
path = cv.markup_file(
url="https://raw.githubusercontent.com/example/repo/main/README.md",
from_format="markdown",
to_format="html",
gfm=True,
sanitize=True,
output_path="readme.html",
)
print(f"Saved to {path}")
Extract table of contents from Markdown¶
The response includes a toc list when converting Markdown or HTML to HTML.
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
result = cv.markup(
from_format="markdown",
to_format="html",
content="# Introduction\n## Setup\n## Usage\n## FAQ",
)
for item in result.get("metadata", {}).get("toc", []):
print(f"{' ' * (item['level'] - 1)}{item['text']}")
# Introduction
# Setup
# Usage
# FAQ
Request Parameters¶
| Parameter | Type | Description |
|---|---|---|
from_format |
string | Source format: markdown, html, text |
to_format |
string | Target format: markdown, html, text |
content |
string | Inline markup content |
url |
string | Public URL to fetch source content from (alternative to content) |
gfm |
boolean | Enable GitHub Flavored Markdown extensions (tables, strikethrough, etc.) |
sanitize |
boolean | Strip potentially unsafe HTML tags and attributes |
preserve_links |
boolean | Keep anchor tags when converting HTML to Markdown |
preserve_tables |
boolean | Keep table formatting when converting HTML to Markdown |
Response Fields¶
| Field | Type | Description |
|---|---|---|
result |
string | The converted content as a string |
from_format |
string | Source format used |
to_format |
string | Target format used |
metadata |
object | Stats including word_count, char_count, and toc array |
Tip
Pass sanitize=True whenever processing user-supplied content before rendering it in a browser — it removes dangerous tags while keeping all safe formatting intact.