Skip to content
POST
/api/v1/format

Format markdown API

Beautify and normalise a markdown document.

POST /api/v1/format is the Markdown Viewer API endpoint for beautifying markdown: trims trailing whitespace, normalises bullets and headings, collapses excessive blank lines, and ensures consistent task-list syntax — all without changing the document's meaning.

Overview

Applies a conservative set of fixes: trims trailing whitespace, normalises bullet style to `-`, collapses 3+ blank lines into one, ensures a space after ATX heading hashes, and normalises task-list checkboxes.

Request

Authenticate with Authorization: Bearer YOUR_API_KEY and send a JSON body containing the parameters below. Pick your language:

curl -X POST 'https://trymarkdownviewer.com/api/v1/format' \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"markdown":"##Heading\n*  item one\n\n\n* item two"}'

Body parameters

FieldTypeRequiredDescription
markdownstring
required
Markdown source.

Response

Success responses are wrapped in a data field. Errors use { error: { code, message } } with an appropriate HTTP status — see the error reference.

{
  "data": {
    "formatted": "## Heading\n\n- item one\n\n- item two\n",
    "changed": true
  }
}

Use cases

Editor save-time formatting

Pipe content through /api/v1/format when a user saves to enforce a consistent style across a team's content.

CI / pre-commit hook

Auto-format markdown in pull requests so reviewers focus on substance, not whitespace or bullet style.

Migration & normalisation

Clean up imports from legacy CMS systems or scraped sources — make the markdown look like it was written today.

Production tips

  • The `changed` flag in the response tells you whether anything was modified — skip the write if false.
  • Formatting is deterministic and idempotent: running format on the output is a no-op.
  • The document's semantic meaning is preserved — only whitespace, bullet style, and heading spacing are touched.

Format markdown FAQ

Will /api/v1/format change the meaning of my markdown?
No. The formatter only normalises whitespace, bullet style, ATX heading spacing, task-list checkboxes, and consecutive blank lines. Inline structure, links, code blocks, and tables are left untouched.
Is the formatter configurable?
Not currently — we ship one opinionated, conservative ruleset so you don't have to maintain a config file. If you need a specific style, open an issue and we'll consider it.
Can I run it locally without making an API call?
Yes. The format engine is the same one our open-source editor uses. You can self-host the rendering engine from the GitHub repo if you want zero round-trips.

Try in browser

Free tools that run the same logic locally — no API key, no upload.

Try it

Send a real request against your account in the API playground. Errors there link straight back to the error reference.