Return the [start, end) bounds for a Markdown H2 section. Uses ``_iter_h2_headings`` so the same H2 detection that finds the target heading also determines the section's end (the next H2). A drifted ``"## Documents "`` matches ``"## Documents"`` because both sides are normalized.
(lines: list[str], heading: str)
| 782 | |
| 783 | |
| 784 | def _get_section_bounds(lines: list[str], heading: str) -> tuple[int, int] | None: |
| 785 | """Return the [start, end) bounds for a Markdown H2 section. |
| 786 | |
| 787 | Uses ``_iter_h2_headings`` so the same H2 detection that finds the |
| 788 | target heading also determines the section's end (the next H2). A |
| 789 | drifted ``"## Documents "`` matches ``"## Documents"`` because both |
| 790 | sides are normalized. |
| 791 | """ |
| 792 | headings = _iter_h2_headings(lines) |
| 793 | for k, (idx, normalized) in enumerate(headings): |
| 794 | if normalized == heading: |
| 795 | start = idx + 1 |
| 796 | end = headings[k + 1][0] if k + 1 < len(headings) else len(lines) |
| 797 | return start, end |
| 798 | return None |
| 799 | |
| 800 | |
| 801 | def _ensure_h2_section(lines: list[str], heading: str, *, quiet: bool = False) -> None: |
no test coverage detected