Markdown Code Block Extractor
Extract all fenced code blocks from Markdown — see language, line count, and copy or download each snippet.
javascript
4 lines
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("World"));
bash
3 lines
#!/bin/bash echo "Installing application..." npm install && npm run build
json
5 lines
{
"name": "my-app",
"version": "1.0.0",
"private": true
}
Total Blocks
3
Total Lines
12
Languages
3
Avg Lines/Block
4
About Markdown Code Block Extractor
Fenced code blocks in Markdown are delimited by triple backticks (```) or tildes (~~~) optionally followed by a language identifier. This tool parses your Markdown and extracts every fenced block, showing the language tag, line count, and the raw code content. Useful for pulling code snippets out of documentation, README files, or tutorial posts without manually scanning the source. Inline code (single backtick) is intentionally ignored — only fenced blocks are extracted.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Pulling every snippet out of a tutorial to run them in order.
- Extracting code from documentation to test that it still works.
- Collecting the shell commands from a README into a script.
- Checking which languages a document's blocks are tagged with.
- Getting the code out of a long answer without scrolling and copying.
Frequently Asked Questions
- What does it pull out of a document?
- Every fenced code block, with its language tag, in order. That is the practical unit — extracting the code from a tutorial or an AI response so it can be run, without hand-selecting each block and losing the language association.
- How are nested fences handled?
- By fence length. CommonMark allows a longer fence to contain a shorter one, so a block documenting Markdown itself uses four backticks to wrap three. A parser that matches the first closing fence it sees truncates exactly those documents.
- What is the info string?
- Everything after the opening fence — conventionally the language, but it may carry more: a filename, line highlights, or a flag some renderers act on. Only the first word is the language, which is why splitting on whitespace matters when reading it.
- Are indented code blocks recognised?
- They are a separate CommonMark construct — four spaces of indentation with no fence and no language. They cannot carry a language tag at all, which is one reason fenced blocks became the convention everywhere the language matters.
- Why extract rather than copy by hand?
- Because a long answer or README often contains a dozen blocks in several languages, and separating the shell commands from the config from the code is exactly the mechanical step that invites mistakes when done by eye.
Common errors and gotchas
- Assuming untagged blocks are one language, when a document often mixes several.
- Running extracted commands without reading them, which is how a tutorial deletes something.
- Losing the surrounding context that said which blocks are alternatives rather than sequential.
- Overlooking indented code blocks, which are not fenced and may be missed.
- Extracting a block whose content was deliberately shown as wrong.
Related Developer Utilities tools
RegExp Tester
Test regular expressions and inspect matches locally.
Regex Visualizer
Visual regex pattern diagram with live match highlighting and capture group annotations.
Subnet Calculator
Compute CIDR subnets, usable hosts, and network ranges.
Cron Parser
Translate cron syntax into plain English.
URL Parser
Break a URL into protocol, host, path, and query parts.
HTML Previewer
Paste HTML and see it rendered live in a safe, sandboxed preview.
HTTP Status Code Reference
Search and look up every HTTP status code and its meaning.
MIME Type Lookup
Find the MIME type for a file extension, or the extensions for a MIME type.