Code Block Extractor
Extract every fenced code block from a Markdown document
Pull JavaScript, Python, Bash, JSON, Dockerfile, SQL, Mermaid, and 25+ other fenced languages out of any Markdown file. Filter by language, copy individual blocks, or download each as a real source file with the right extension.
jsL31 line(s)function add(a, b) { return a + b; }pythonL92 line(s)def add(a, b):
return a + bbashL141 line(s)npm install my-package
jsonL181 line(s){ "ok": true }How to use the code extractor
- Paste Markdown or click Open .md to load a file.
- The tool lists every fenced code block with its language, starting line, and line count.
- Use the language pills to filter — show only
bash, onlypython, etc. - For each block: Copy the body to clipboard, or Download with a sensible filename.
- Use Copy all (as Markdown) to grab the visible blocks back as a fenced Markdown stream.
When this saves real time
- Tutorial → runnable repo. A long step-by-step doc with ten bash + JS + JSON blocks becomes a real project in minutes.
- Docs → tests. Pull snippets out of ```js fences and seed unit tests so prose and examples stay in sync.
- README extraction. Quickly grab every Dockerfile / CI config example for review.
- Cross-doc reuse. Cherry-pick the relevant snippet from a long migration guide for a different page.
Supported languages and extensions
The mapping covers the languages people actually paste into Markdown: JavaScript, TypeScript, Python, Go, Rust, Ruby, Java, Kotlin, Swift, Bash/Shell, PowerShell, C, C++, C#, PHP, JSON, YAML, TOML, CSS, SCSS, HTML, SQL, Dockerfile, GraphQL, Mermaid, TeX, diff, and patch.
Unknown languages fall back to .txt — rename after download.
Companion tools
- Diagram Inventory & Mermaid Validator — focused inventory for Mermaid and math fences.
- Markdown Outline Reorder — restructure the document around the extracted snippets.
- Markdown Editor — paste a snippet back to see it rendered.
Privacy & data
Extraction is a small client-side parser. We don't upload, log, or store the Markdown you paste.
Frequently asked questions
- Common reasons: turning a tutorial into a runnable sample folder, harvesting snippets from a doc for unit tests, copying just the bash commands from a long installation guide, or migrating a single doc into multiple per-language code files.
- From the fence's language tag — the text after the triple backticks (`\`\`\`js`, `\`\`\`python`, etc.). Blocks without a language tag are labeled `plaintext`. The filter pills show counts per language so you can quickly isolate one type.
- Each block gets a suggested filename based on the language (e.g., `snippet-3.py`, `snippet-7.go`, `Dockerfile`). The default name combines the block index and the extension — adjust as needed before saving.
- Yes. The extractor copies the exact body between the fences. Trailing whitespace and tab indentation are preserved byte-for-byte.
- Click 'Copy all (as Markdown)' to grab every visible block re-wrapped in their fences — handy for moving snippets between docs. For a full filesystem export, download each block individually; a multi-file ZIP would require uploading the content, which we deliberately avoid.
- No. Extraction is a string-parse operation that runs entirely in your browser.
Why extract code from Markdown?
How are languages detected?
Are filenames safe to use?
Does it preserve indentation and whitespace?
Can I export everything at once?
Is the document uploaded?
Related tools
More free browser tools in the same workflow.
Use the API
Automate this workflow in your app with the same engine that powers these browser tools.
New to the platform? Start with the API quickstart, then try a live request in the API playground.
Explore the API platform