Split text into sections at markdown header lines (# or ##). Returns a list of (start_line, section_text) tuples where start_line is the 1-indexed line number of the first line in the section.
(text: str)
| 61 | |
| 62 | |
| 63 | def _split_sections(text: str) -> list[tuple[int, str]]: |
| 64 | """Split text into sections at markdown header lines (# or ##). |
| 65 | |
| 66 | Returns a list of (start_line, section_text) tuples where start_line |
| 67 | is the 1-indexed line number of the first line in the section. |
| 68 | """ |
| 69 | lines = text.split("\n") |
| 70 | sections: list[tuple[int, str]] = [] |
| 71 | current_start = 1 |
| 72 | current_lines: list[str] = [] |
| 73 | |
| 74 | for i, line in enumerate(lines): |
| 75 | if re.match(r"^#{1,2} ", line) and current_lines: |
| 76 | sections.append((current_start, "\n".join(current_lines))) |
| 77 | current_start = i + 1 |
| 78 | current_lines = [line] |
| 79 | else: |
| 80 | current_lines.append(line) |
| 81 | |
| 82 | if current_lines: |
| 83 | sections.append((current_start, "\n".join(current_lines))) |
| 84 | |
| 85 | return sections |
| 86 | |
| 87 | |
| 88 | def clean_mandoc_artifacts(text: str) -> str: |
no test coverage detected