/api/v1/extract/code-blocksExtract code blocks API
Fenced code with language and suggested filename.
POST /api/v1/extract/code-blocks isolates every fenced code block from markdown — language, body, start line, and a filename suggestion. Perfect for tangling code from docs into runnable files.
Overview
Pull every fenced code block out as a structured object: language tag, source body, start line, and a suggested filename based on the language. Ideal for snippet runners, docs validators, and AI tooling.
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/extract/code-blocks' \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"markdown":"```js\nconsole.log(1);\n```"}'Body parameters
| Field | Type | Required | Description |
|---|---|---|---|
| markdown | string | 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": {
"blocks": [
{
"index": 1,
"lang": "js",
"startLine": 1,
"body": "console.log(1);",
"suggestedFilename": "snippet-1.js"
}
],
"count": 1
}
}Use cases
Literate programming
Tangle code out of a doc into runnable files.
Docs CI
Run extracted snippets through a linter or test runner.
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.