MCPcopy Create free account
hub / github.com/Qinbf/groundmap / read_section

Function read_section

scripts/k.py:1578–1597  ·  view source on GitHub ↗

根据 anchor 或 title 取出整段 H 段(到下一同级 heading 之前)。

(md_path: Path, anchor_or_title: str)

Source from the content-addressed store, hash-verified

1576
1577
1578def read_section(md_path: Path, anchor_or_title: str) -> dict:
1579 """根据 anchor 或 title 取出整段 H 段(到下一同级 heading 之前)。"""
1580 outline = load_or_build_outline(md_path)
1581 sec = find_section_in_outline(outline["sections"], anchor_or_title)
1582 if not sec:
1583 raise LookupError(f"未找到 anchor 或标题: {anchor_or_title}")
1584 text = md_path.read_text(encoding="utf-8")
1585 body = text[sec["char_start"]:sec["char_end"]]
1586 return {
1587 "path": _to_rel_posix(md_path),
1588 "anchor": sec["anchor"],
1589 "title": sec["title"],
1590 "level": sec["level"],
1591 "line": sec["line"],
1592 "char_start": sec["char_start"],
1593 "char_end": sec["char_end"],
1594 "preview": sec.get("preview", ""),
1595 "agent_summary": sec.get("agent_summary"),
1596 "content": body,
1597 }
1598
1599
1600def _anchor_hash6(anchor: str) -> str | None:

Callers 1

_main_implFunction · 0.70

Calls 3

load_or_build_outlineFunction · 0.85
find_section_in_outlineFunction · 0.85
_to_rel_posixFunction · 0.85

Tested by

no test coverage detected