/api/v1/generate/tocGenerate table of contents API
Markdown TOC from headings.
POST /api/v1/generate/toc builds a Markdown table of contents from a document's headings. Level range, marker style, ordered/unordered, and indent size are all configurable.
Overview
Build a Markdown TOC ready to paste into a README or inject between `<!-- TOC -->` markers. Level range, ordered vs. unordered, marker style, and indentation are all configurable.
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/generate/toc' \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"markdown":"# H1\n\n## A\n\n## B"}'Body parameters
| Field | Type | Required | Description |
|---|---|---|---|
| markdown | string | required | Markdown source. |
| minLevel | 1..6 | optional | Lowest heading level to include. Default 2. |
| maxLevel | 1..6 | optional | Highest heading level to include. Default 6. |
| ordered | boolean | optional | Use `1.` instead of `-`. |
| marker | "-" | "*" | "+" | optional | Unordered list marker. |
| indentSize | 2 | 4 | optional | Spaces per nesting level. |
Response
Success responses are wrapped in a data field. Errors use { error: { code, message } } with an appropriate HTTP status — see the error reference.
{
"data": {
"toc": "- [A](#a)\n- [B](#b)\n",
"headingCount": 2
}
}Use cases
README automation
Inject TOCs between marker comments in a docs build step.
Related endpoints
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.