Modifier Blocks
Extract Markdown Code Blocks
Extract code blocks from markdown-formatted text
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
The markdown-formatted text from which to extract code blocks.
Outputs
The first code block found in the input markdown. If no code blocks are found, this output will be control-flow-excluded.
An array of strings, where each string represents a code block extracted from the input markdown.
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
- Create a new flow and add an Extract Markdown Code Blocks block.
- Add a Text block with markdown content containing code blocks and connect it to the
input
of the Extract Markdown Code Blocks block. - Connect any of the outputs to view the extracted code blocks or language information.
- 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 andallBlocks
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.