MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _iter_h2_headings

Function _iter_h2_headings

openkb/agent/compiler.py:770–781  ·  view source on GitHub ↗

Return ``[(line_index, normalized_heading), ...]`` for every ATX H2. A line counts as H2 when it starts with ``"## "`` (two hashes + space). ``normalized_heading`` is the line with trailing whitespace stripped, so ``"## Documents "`` normalizes to ``"## Documents"`` — letting callers

(lines: list[str])

Source from the content-addressed store, hash-verified

768
769
770def _iter_h2_headings(lines: list[str]) -> list[tuple[int, str]]:
771 """Return ``[(line_index, normalized_heading), ...]`` for every ATX H2.
772
773 A line counts as H2 when it starts with ``"## "`` (two hashes + space).
774 ``normalized_heading`` is the line with trailing whitespace stripped, so
775 ``"## Documents "`` normalizes to ``"## Documents"`` — letting callers
776 use exact-string comparison without tripping on stray whitespace.
777
778 Used by ``_get_section_bounds`` so heading lookup and the next-section
779 boundary share one scan and one normalization rule.
780 """
781 return [(i, line.rstrip()) for i, line in enumerate(lines) if line.startswith("## ")]
782
783
784def _get_section_bounds(lines: list[str], heading: str) -> tuple[int, int] | None:

Callers 1

_get_section_boundsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected