Markdown Code Block Parser icon

Markdown Code Block Parser

Parse all code blocks from Markdown text

Markdown Code Block Parser

AI-generated

Overview

This node parses all code blocks from a given Markdown text input. It extracts code blocks enclosed in triple backticks or tildes, optionally filtering by whether the blocks are empty or lack a language identifier. The node is useful for scenarios where you need to extract and process code snippets embedded in Markdown documents, such as documentation parsing, code analysis, or automated code extraction workflows.

Use Case Examples

  1. Extract all code blocks from a Markdown README file to analyze or transform the code snippets.
  2. Parse Markdown content from a blog post to separate code examples for syntax highlighting or further processing.
  3. Filter and output only non-empty code blocks with language identifiers for automated testing or code review.

Properties

Name Meaning
Markdown Text The Markdown text to parse for code blocks. This is the main input containing the Markdown content.
Output Field Name The name of the output field that will contain the array of parsed code blocks. If left empty, each code block is output as a separate item.
Include Empty Blocks Whether to include empty code blocks in the output. If false, empty code blocks are excluded.
Include Blocks Without Language Whether to include code blocks that do not have a language identifier specified after the opening fence.

Output

JSON

  • code - The extracted code content of the code block.
  • language - The language identifier specified for the code block, if any.
  • index - The zero-based index of the code block in the parsed list.
  • fence - The fence characters used to delimit the code block (e.g., ``` or ~~~).
  • startLine - The line number in the original Markdown text where the code block starts.
  • endLine - The line number in the original Markdown text where the code block ends.

Troubleshooting

  • Ensure the Markdown text input is not empty; the node throws an error if the Markdown text is missing.
  • If no code blocks are found, verify the Markdown text contains properly fenced code blocks using triple backticks or tildes.
  • If outputting code blocks as separate items, an empty output array means no code blocks matched the filter criteria (empty blocks or language filters).
  • If using an output field name, ensure it does not conflict with existing fields in the input data to avoid overwriting.

Discussion