Code Block Extractor
The Code Block Extractor component helps you pull out code snippets that are wrapped in triple backticks (```) from a larger block of text. This is useful when you have a document or a chat message that contains code and you want to isolate that code for further processing or execution.
How it Works
When you drop text into the component, it looks for a section that starts with three backticks. It can handle plain or
language. The component then captures everything between the opening and closing backticks and returns it as the output. All of this happens right inside the dashboard – no external services are called.
Inputs
- text: The full text that may contain one or more code blocks. Paste or connect the output of another component that provides the text you want to scan.
Outputs
- Code Block: The extracted code snippet. If the input text contains no code block, this output will be empty. You can feed this output into other components that run or analyze code.
Usage Example
- Drag the Code Block Extractor onto the canvas.
- Connect a Text Input component (or any component that outputs text) to its text input.
- The Code Block output will now contain the code inside the first set of triple backticks it finds.
- Connect that output to a Code Runner or Syntax Highlighter component to execute or display the code.
Related Components
- Text Input – Provides the raw text that may contain code.
- Code Runner – Executes the extracted code.
- Syntax Highlighter – Formats the code for display.
Tips and Best Practices
- Make sure the code block in your text is surrounded by triple backticks; otherwise the component will not find it.
- If your text contains multiple code blocks, the component will only return the first one it encounters.
- Use the output of this component as the input for a Code Runner to test the extracted snippet quickly.
Security Considerations
The component only extracts text; it does not execute or evaluate it. However, if you plan to run the extracted code, ensure you trust the source of the text to avoid running malicious code. Use sandboxed environments or code review steps before execution.