(input_text)
| 1 | # Remove everything outside the first ``` code block containing a function. |
| 2 | def extract_code_from_md(input_text): |
| 3 | output = [] |
| 4 | code_block = False |
| 5 | found_def = False |
| 6 | for line in input_text.splitlines(): |
| 7 | if line.strip().startswith("```"): |
| 8 | if found_def: |
| 9 | break |
| 10 | code_block = not code_block |
| 11 | if code_block: |
| 12 | found_def = False |
| 13 | output.clear() |
| 14 | elif code_block: |
| 15 | output.append(line) |
| 16 | if 'def' in line: |
| 17 | found_def = True |
| 18 | return '\n'.join(output) |
no outgoing calls