String Utilities 도구 업데이트됨 3일 전

Markdown Code Block Extractor

Extract every fenced code block from a Markdown document. The tool reads backtick and tilde fences, records the language from each info string, and returns the code as a JSON array you can review in a table, copy, or download as markdown-code-blocks.json. Everything runs in your browser.

항상 무료 사용하기 쉬움 즉각적인 결과 비공개이며 안전합니다

사용법 Markdown Code Block Extractor

마크다운 코드 블록 추출기

울타리로 둘러싸인 마크다운 코드 블록, 언어 및 원시 코드를 구조화된 JSON으로 추출합니다.

마크다운 입력

펜스 처리된 코드 블록이 포함된 마크다운 붙여넣기
다음과 같은 방식으로 울타리가 쳐진 블록을 지원합니다. ``` 그리고 ~~~. 언어는 펜스 정보 문자열에서 읽어옵니다.
아직 추출되지 않았습니다
추출 상태
0 블록
추출된 코드 블록

추출된 블록

각 블록별 언어 및 코드 미리보기
# 언어 코드
아직 추출 작업이 실행되지 않았습니다.
코드 추출 팁
이 도구는 헨지된 코드 블록만 추출합니다. 다음과 같은 인라인 코드는 `example` 의도적으로 무시됩니다.
도구 링크
클립보드에 복사되었습니다.
이 도구를 개선하는 데 도움을 주세요

내용 읽기

이 도구의 작동 방식과 사용 시기를 알아보세요.

Pull every fenced code sample out of a Markdown file

Technical writing is full of code. A single README might hold install commands, a config file, a short PHP class and a curl request, each sitting inside its own fenced block. The Markdown Code Block Extractor reads a Markdown document, finds every fenced block, and returns the code together with the language tag in a clean JSON array. You can scan the results in a table, copy the JSON, or download it as a file for further processing.

It is useful whenever the code matters more than the prose around it: testing documentation snippets, building a snippet library, moving examples into a test suite, or simply checking which languages a long guide actually uses.

What counts as a code block

The extractor looks for fences, the lines that open and close a block:

  • Backtick fences: three or more backticks, as in ```.
  • Tilde fences: three or more tildes, as in ~~~.

The text that follows the opening fence on the same line is the info string. The tool takes the first word of it as the language, so ```js title="app.js" is recorded as js. A fence with no info string gets a language of null in the JSON and shows as "(none)" in the table.

Leading spaces before a fence are tolerated, so fences inside list items are picked up. A block is closed by the next fence line of the same kind: a backtick block ends at the next backtick fence, a tilde block at the next tilde fence. If a block is never closed, everything from the opening fence to the end of the document is captured as that block, which is the same way most Markdown renderers treat an unclosed fence.

Two kinds of code are deliberately left out. Inline code such as `npm install` inside a sentence is ignored, and so are indented code blocks made with four leading spaces and no fence. The tip at the bottom of the page states the inline rule plainly: this tool extracts fenced code blocks only.

The JSON format

Each block becomes one object with two keys, in the order the blocks appear in your document:

[{"language": "bash", "code": "npm install\nnpm run build"}, {"language": null, "code": "plain text block"}]

The code value is the exact text between the fences with the original line breaks and indentation preserved. Windows line endings are normalised to plain line feeds first. The fence lines themselves are not included.

Using the tool

  1. Paste your Markdown into the Input Markdown editor, or press Paste in the header to pull it from your clipboard. The footer shows the character count and a rough "possible blocks" figure that counts fence lines and halves the result.
  2. Press Extract.
  3. Read the Extracted Blocks table. Each row shows the block number, the language badge and a preview of the code.
  4. Check the status cards. Extraction status says "Code blocks extracted" or "No code blocks found", and Extracted code blocks gives the total.
  5. Press Copy JSON to copy the array, or Download JSON to save it as markdown-code-blocks.json.

Two smaller buttons sit on the input card: Copy Input copies what you pasted, and Clear empties the input, the table and the JSON. Editing the input after an extraction resets the results, so the table always matches the text currently in the editor. Press Extract again after any change.

Where the work happens

Extraction runs entirely in your browser in plain JavaScript, line by line. Your Markdown is not uploaded to this site's server, which makes the tool safe for internal docs and unreleased code samples. There is no server-side size limit; very large documents are limited only by what your browser and the editor handle comfortably.

Things people do with the output

Testing the examples in your docs

Documentation rots when code samples stop working. Feed the JSON into a small script that picks every python or bash block and runs it in a sandbox. Failures point straight at the snippet that needs fixing.

Building a snippet library

Extract blocks from a collection of notes or blog posts, filter by language, and import them into a snippet manager or a team knowledge base.

Auditing language tags

Syntax highlighting depends on the info string. Running a long guide through the extractor quickly shows blocks with no language or with inconsistent tags like sh, shell and bash side by side, so you can standardise them.

Preparing training or evaluation data

Researchers and teams building prompt sets often need code separated from prose. The array is already in a shape most scripts can read directly.

Copying a single command

Sometimes you just want the commands from an install guide without scrolling. The table gives you every block in one place.

Tips for accurate results

  • Always tag your fences with a language. It makes the JSON far more useful and improves highlighting everywhere the Markdown is rendered.
  • If the possible blocks count is not a whole match for the number you expect, look for a missing closing fence. An odd number of fence lines usually means one block swallows the rest of the file.
  • When you need to show a fence inside a code block, use the other fence type for the outer block, for example a tilde block that contains backtick lines. That keeps the inner fence from closing the outer block early.
  • Download the JSON when you plan to process it with a script. Copying from the editor works too, but a file avoids clipboard size limits on very long outputs.

What to avoid

  • Do not expect indented code blocks to appear. Convert them to fenced blocks first if you need them extracted.
  • Do not nest a backtick fence of four backticks around one of three and expect the inner one to survive. The tool compares only the first three characters of a fence, so any backtick fence line closes an open backtick block.
  • Do not use the table preview as your source of truth for exact characters. Copy from the Raw JSON editor or the downloaded file, which hold the code exactly as extracted.
  • Do not paste secrets you would not want in a clipboard history. The tool itself keeps nothing, but copying puts the text on your clipboard.

Limitations

  • Fenced blocks only; inline code and four-space indented blocks are ignored.
  • Only the first word of the info string is kept. Attributes such as titles or line highlights after the language are dropped.
  • Closing fences are matched by type, not by length.
  • Code inside HTML <pre> tags embedded in the Markdown is not detected.
  • The output format is JSON only. There is no option to export each block as a separate file.

Related tools

If you want the opposite result, a document with the code removed, try Markdown Remove Code Blocks. To list headings so you can tell which section each snippet belongs to, use the Markdown Heading Extractor.

Frequently Asked Questions

자주 묻는 질문

사용자가 결과를 신뢰하기 전에 자주 묻는 질문에 대한 간결한 답변.

Yes. Fences of three or more backticks and fences of three or more tildes are both recognised, and each block closes at the next fence of the same type.

It is read from the info string after the opening fence. Only the first word is kept, so a fence written as js title="app.js" is recorded as js. Blocks with no info string get null.

The tool extracts fenced blocks only. Inline code between single backticks is intentionally skipped, as are indented blocks without a fence.

Everything from the opening fence to the end of the document is captured as one block. A mismatch between the possible blocks count and what you expect is a good hint that a fence is missing.

No. The extraction runs in your browser with JavaScript, and the text is not sent to this site's server.

Download JSON saves the results as markdown-code-blocks.json, an array of objects with language and code keys.

Yes. The code value keeps every line between the fences exactly as written, including blank lines and leading spaces. Only Windows line endings are converted to plain line feeds.

댓글 (0)

사용자 토론, 예외적인 사례 및 추가 팁을 위한 공간입니다.
댓글 남기기
댓글을 제출하면 공개적으로 표시됩니다.
아직 댓글이 없습니다. 가장 먼저 댓글을 남겨보세요!
저희에게 알려주세요!
이 도구와 관련된 문제를 신고하기

발생한 문제를 자세히 설명해 주시면, 저희가 이를 조사하고 도구를 개선할 수 있습니다.

가장 도움이 되는 것은 무엇인가
입력 내용, 예상 결과, 실제 결과, 브라우저/기기 정보를 기재해 주시고, 도움이 될 경우 스크린샷도 첨부해 주세요.
스크린샷 버튼은 브라우저에 표시된 페이지를 캡처하여 생성된 이미지를 이 양식에 첨부합니다.
전체 화면 스크린샷
newisty를 통해 브라우저에서 캡처되었습니다.
아직 스크린샷을 찍지 않았습니다.
도구 보고서