Open the context
Choose the project folder and name the files or behavior involved.
Extract column-zero triple-backtick blocks from text of at most 4096 characters with optional ASCII language labels. Test empty blocks and normalized line breaks, reject an unclosed block and leave unsupported Markdown forms uninterpreted without executing code.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
import re
def fenced_blocks(text):
if type(text) is not str or len(text) > 4096:
raise ValueError("fence.input")
blocks, body, language = [], None, None
for line in text.splitlines():
if body is None:
opening = re.fullmatch(r"```([A-Za-z0-9_-]*)", line)
if opening:
body, language = [], opening[1]
elif line == "```":
blocks.append((language, "\n".join(body)))
body = None
else:
body.append(line)
if body is not None:
raise ValueError("fence.unclosed")
return blocks
The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.