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.
4 fenced block(s) · 4 language(s)
Block 1
jsL31 line(s)function add(a, b) { return a + b; }Block 2
pythonL92 line(s)def add(a, b):
return a + bBlock 3
bashL141 line(s)npm install my-package
Block 4
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.