Text

Markdown to HTML

0calls
1 credits / call

Call this endpoint directly to convert Markdown text to styled HTML. It's not only suitable for dynamic injection in programs, but also for direct preview during development.

POST
uapis.cn
/api/v1/text/markdown-to-html
Body
text
string
required

Raw Markdown string, maximum size not exceeding 1MB.

format
string

Response format. Pass json to return JSON-wrapped HTML fragment; pass html to directly return text/html, and response content will automatically include complete webpage structure, suitable for browser preview or direct save as webpage file. Default is json.

sanitize
boolean

Whether to enable security mode, filtering out risky scripts in user input. Default is true.

How to Use and Preview

  • Default Mode: Returns HTML fragment in JSON: When format is not passed, the endpoint returns JSON. You just need to read data.html from the response and assign it to the frontend container, e.g., element.innerHTML = data.html, Vue's v-html, or React with dangerouslySetInnerHTML.
  • Preview Mode: Directly returns complete HTML webpage: If you want to open the result directly in a browser, or save the response as an independent .html file, pass format="html". In this mode, the endpoint will directly return complete webpage source code with <!DOCTYPE html><html>....

Overview

  • Beautiful typography built-in, no need to write CSS manually: The returned results already have built-in styles, titles, quotes, tables, task lists and code blocks can be displayed directly.
  • Supports rich layout elements: In addition to standard Markdown, this endpoint can also correctly handle common GFM syntax, such as tables, task lists and code blocks with language tags.
  • Secure handling of user content: Security mode is enabled by default, automatically filtering risky scripts in raw HTML. If the content source is absolutely trusted and you really need to keep the original HTML, you can set sanitize to false.

Request body

Request body uses application/json. text is required; format and sanitize are optional.

text
stringrequired

Raw Markdown string, maximum size not exceeding 1MB.

format
stringoptional

Response format. Pass json to return JSON-wrapped HTML fragment; pass html to directly return text/html, and response content will automatically include complete webpage structure, suitable for browser preview or direct save as webpage file. Default is json.

sanitize
booleanoptional

Whether to enable security mode, filtering out risky scripts in user input. Default is true.

Response

200 / OK

Conversion successful. Whether JSON or plain HTML is returned depends on the format parameter.

Format 1application/json
JSON
{
  "data": {
    // Converted HTML string, content is styled HTML fragment.
    "html": "<style>...</style><div class=\"uapi-markdown\"><h1 id=\"coffee\">Coffee</h1><p>...</p></div>"
  }
}
Format 2text/html
HTML
<!DOCTYPE html><html lang="en-US"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>Markdown Preview</title></head><body><main><style>...</style><div class="uapi-markdown"><h1 id="coffee">Coffee</h1><p>...</p></div></main></body></html>

400 / Bad Request

Request parameter error. May be request body format error, text is empty, or format value is invalid.

Format 1Request body format error
JSON
{
  "code": "INVALID_PARAMETER",
  "message": "Request body format is incorrect, please pass standard JSON"
}
Format 2Missing Markdown text
JSON
{
  "code": "INVALID_PARAMETER",
  "message": "text cannot be empty"
}
Format 3Response format error
JSON
{
  "code": "INVALID_PARAMETER",
  "message": "format only allows json or html"
}

413 /

Markdown text exceeds current size limit.

JSON
{
  "code": "TEXT_TOO_LARGE",
  "message": "Markdown content cannot exceed 1MB"
}

500 / Internal Server Error

Error occurred during conversion, please try again later.

JSON
{
  "code": "REQUEST_FAILED",
  "message": "Markdown to HTML failed, please try again later"
}

503 / Service Unavailable

Service temporarily unavailable.

JSON
{
  "code": "SERVICE_TEMPORARILY_UNAVAILABLE",
  "message": "Markdown to HTML service is temporarily unavailable, please try again later"
}