Split full text into sections based on heading patterns.
(text: str)
| 146 | |
| 147 | |
| 148 | def _split_sections(text: str) -> dict[str, str]: |
| 149 | """Split full text into sections based on heading patterns.""" |
| 150 | sections: dict[str, str] = {} |
| 151 | current_heading = "Preamble" |
| 152 | current_lines: list[str] = [] |
| 153 | |
| 154 | for line in text.split("\n"): |
| 155 | matched = False |
| 156 | for pattern in _SECTION_PATTERNS: |
| 157 | m = pattern.match(line.strip()) |
| 158 | if m: |
| 159 | # Save previous section |
| 160 | if current_lines: |
| 161 | sections[current_heading] = "\n".join(current_lines).strip() |
| 162 | current_heading = m.group(1).strip() |
| 163 | current_lines = [] |
| 164 | matched = True |
| 165 | break |
| 166 | if not matched: |
| 167 | current_lines.append(line) |
| 168 | |
| 169 | # Save last section |
| 170 | if current_lines: |
| 171 | sections[current_heading] = "\n".join(current_lines).strip() |
| 172 | |
| 173 | return sections |
no test coverage detected