Overview

The Extract Markdown Code Blocks block is designed to parse markdown-formatted text and extract all code blocks within it. This is particularly useful when working with documentation, README files, or any text that contains code snippets in markdown format.

Inputs

input
string
required

The markdown-formatted text from which to extract code blocks.

Outputs

firstBlock
string

The first code block found in the input markdown. If no code blocks are found, this output will be control-flow-excluded.

allBlocks
string[]

An array of strings, where each string represents a code block extracted from the input markdown.

languages
string[]

An array of strings containing the language identifiers specified for each code block. For example, in “```python”, “python” would be the language identifier.

Example: Extracting Code from a README

  1. Create a new flow and add an Extract Markdown Code Blocks block.
  2. Add a Text block with markdown content containing code blocks and connect it to the input of the Extract Markdown Code Blocks block.
  3. Connect any of the outputs to view the extracted code blocks or language information.
  4. Run the flow to see the results.

Error Handling

  • If no code blocks are found in the input markdown, the firstBlock output will be control-flow-excluded and allBlocks will be an empty array.
  • The block will not throw an error for invalid markdown; it will attempt to extract any code blocks it can identify.

FAQ

See Also