pulls fenced ``` code blocks out of Markdown

Extract code blocks from Markdown

Lift every fenced code block out of a Markdown document — optionally filter by language — for snippet libraries, automation, or docs testing.

Code Block Extractor
Input
146 B
19 lines
Output
93 B
8 lines
Status
ready
live
Ratio
0.64×
out/in
input · markdown
output · code blocks
# block 1 (js)
console.log('hi');

# block 2 (python)
print('hi')

# block 3 (bash)
echo done
Quick Start

How to extract code blocks

Scans line by line for ``` fences, captures the language tag and content of each block, and emits them grouped with headers — optionally filtered by language.

  1. 01

    Paste Markdown

    Any doc with fenced code blocks.

    Parsing runs through marked with GFM extensions enabled — tables, task lists, strikethrough, and fenced code blocks all match GitHub’s rendering.

    inputGFMmarkedCommonMarklive
    input · markdownmd · GFM
    ```js
    x=1
    ```
    loaded · GFMGFM · ready
  2. 02

    Filter (optional)

    Type a language to narrow output to one set.

    Soft-break behaviour is configurable: by default a single newline becomes a space (CommonMark), toggle on for chat-style <br> insertion.

    filtersoft-breaksoptionsconfiglive
    lang · optionsjs · live
    only js
    options applied · livelive
  3. 03

    Extract

    Blocks are concatenated with a header comment per snippet.

    The preview is scoped under a .mde class so its CSS doesn’t bleed into the rest of the page. Output HTML is whitespace-controlled for clean diffs.

    extractpreviewscoped CSSrenderstable
    out · renderedcode · ready
    # block 1 (js)
    rendered · liverendered
  4. 04

    Pipe to a runner

    Drop snippets into a test runner or snippet library.

    Export covers both raw Markdown and rendered HTML; downloads stream as text/markdown or text/html via Blob + object URL.

    exportclipboard.md.htmlblob
    ✓ · exportedcode · done
    ✓ shipped
    shipped · ready to shipsuccess
Pro tips

Author Markdown that renders everywhere

GFM is the safe default

GitHub-Flavored Markdown is the de-facto baseline (tables, task lists, strikethrough). CommonMark is stricter but ubiquitous as a fallback.

Soft-break behaviour varies

A single newline is a space in CommonMark, a <br> in GFM. Toggle soft breaks when source matters.

Escape inside code fences

Backticks inside fenced blocks need a longer fence — three becomes four. Use ~~~ if your content has many backticks.

Anchors are slugified

GitHub lowercases, strips punctuation, and joins with hyphens. Duplicate headings get -1, -2 suffixes.

Tables need a header row

The dash row sets alignment (:---, :-:, ---:). Use Table Aligner for diff-friendly columns.

Front matter is YAML

Triple-dash blocks at the top of files are parsed by static-site generators. Use the Front-Matter Validator to catch syntax errors.

Use Cases

When to extract code blocks

Snippets, tests, and learning material.

Docs testing

Run extracted snippets in CI to catch staleness. Render path uses marked with GFM extensions enabled (tables, task lists, strikethrough, autolinks), so what you preview matches what GitHub publishes bit-for-bit. Soft-break behaviour is configurable for chat-style vs prose Markdown.

GFM-compliant

Snippet libraries

Build a personal library from blog posts. Pairs cleanly with the Markdown Cheatsheet for syntax you can't quite remember — callout blocks, footnotes, definition lists. Output stays diff-friendly so style-only changes don't drown out real edits in PRs.

GitHub-perfect

Tutorial pipelines

Bundle examples into source files automatically. Cross-platform safe: anchors, code fences, and tables behave identically on GitHub, GitLab, Bitbucket, and Gitea. Heading-anchor slugs follow GitHub's lowercase-and-hyphenate rules so deep links survive a docs migration.

diff-friendly

Translation prep

Isolate code from prose for translators. No server roundtrip — perfect for proprietary content you can't paste into a public tool. The full marked + GFM bundle ships with the page, so it works offline once loaded.

i18n

Lint sweep

Lint code separately from the surrounding doc. Front matter (YAML / TOML / JSON) passes through unchanged so static-site pipelines (Jekyll, Hugo, Astro, Eleventy) read it correctly. Pair with the Front-Matter Validator to catch syntax errors before deploy.

cross-platform

REPL replay

Replay a notebook-style doc in your shell. Output is reproducible: identical input always produces identical Markdown, so doc-generation scripts can rely on it for snapshot tests and embedded into release workflows.

SEO-friendly
FAQ

Frequently asked questions

Triple-backtick fences (```). Tilde fences (~~~) are not currently parsed.
No — only fenced blocks. Convert indented blocks to fenced first.
Exact, case-insensitive match against the language tag on the opening fence.
No — Markdown fences can't truly nest. Use four-backtick fences manually if needed.
No. Extraction runs locally in your browser.
Suggest a tool

Something missing?

Tell us what you need. We ship the top requests every two weeks.

Sent straight to the maintainers · no account needed
47 in queue·8 shipped this month
Request queued. Thanks!