Skip to content
POST
/api/v1/generate/toc

Generate 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

FieldTypeRequiredDescription
markdownstring
required
Markdown source.
minLevel1..6optionalLowest heading level to include. Default 2.
maxLevel1..6optionalHighest heading level to include. Default 6.
orderedbooleanoptionalUse `1.` instead of `-`.
marker"-" | "*" | "+"optionalUnordered list marker.
indentSize2 | 4optionalSpaces 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.

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.