逐行分类:blank / heading / hr / fence / text / fence-mid。
(lines: list[str])
| 73 | |
| 74 | |
| 75 | def _classify_lines(lines: list[str]) -> list[str]: |
| 76 | """逐行分类:blank / heading / hr / fence / text / fence-mid。""" |
| 77 | out = [] |
| 78 | in_fence = False |
| 79 | fence_marker = None |
| 80 | for line in lines: |
| 81 | if in_fence: |
| 82 | if fence_marker and line.startswith(fence_marker): |
| 83 | out.append("fence-end") |
| 84 | in_fence = False |
| 85 | fence_marker = None |
| 86 | else: |
| 87 | out.append("fence-mid") |
| 88 | continue |
| 89 | m = FENCE_RE.match(line) |
| 90 | if m: |
| 91 | out.append("fence-start") |
| 92 | in_fence = True |
| 93 | fence_marker = m.group(1) |
| 94 | continue |
| 95 | stripped = line.strip() |
| 96 | if not stripped: |
| 97 | out.append("blank") |
| 98 | elif HEADING_RE.match(line): |
| 99 | out.append("heading") |
| 100 | elif HR_RE.match(stripped): |
| 101 | out.append("hr") |
| 102 | else: |
| 103 | out.append("text") |
| 104 | return out |
| 105 | |
| 106 | |
| 107 | def split_blocks(text: str) -> list[Block]: |