返回 (起始行号, 代码内容, 是否 skip) 三元组列表。
(md_path: Path)
| 21 | |
| 22 | |
| 23 | def extract_blocks(md_path: Path) -> list[tuple[int, str, bool]]: |
| 24 | """返回 (起始行号, 代码内容, 是否 skip) 三元组列表。""" |
| 25 | text = md_path.read_text(encoding="utf-8") |
| 26 | blocks: list[tuple[int, str, bool]] = [] |
| 27 | for m in BLOCK_RE.finditer(text): |
| 28 | skip = m.group(1) is not None |
| 29 | line_no = text[: m.start()].count("\n") + 1 |
| 30 | blocks.append((line_no, m.group(2), skip)) |
| 31 | return blocks |
| 32 | |
| 33 | |
| 34 | def run_block(code: str, timeout: int = 10) -> tuple[bool, str]: |