Skip to content

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 1jsL31 line(s)
function add(a, b) { return a + b; }
Block 2pythonL92 line(s)
def add(a, b):
    return a + b
Block 3bashL141 line(s)
npm install my-package
Block 4jsonL181 line(s)
{ "ok": true }

How to use the code extractor

  1. Paste Markdown or click Open .md to load a file.
  2. The tool lists every fenced code block with its language, starting line, and line count.
  3. Use the language pills to filter — show only bash, only python, etc.
  4. For each block: Copy the body to clipboard, or Download with a sensible filename.
  5. 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

Privacy & data

Extraction is a small client-side parser. We don't upload, log, or store the Markdown you paste.

Frequently asked questions

Why extract code from Markdown?
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.
How are languages detected?
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.
Are filenames safe to use?
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.
Does it preserve indentation and whitespace?
Yes. The extractor copies the exact body between the fences. Trailing whitespace and tab indentation are preserved byte-for-byte.
Can I export everything at once?
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.
Is the document uploaded?
No. Extraction is a string-parse operation that runs entirely in your browser.

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