MCPcopy Create free account
hub / github.com/VectifyAI/PageIndex / _get_md_page_content

Function _get_md_page_content

pageindex/retrieve.py:56–76  ·  view source on GitHub ↗

For Markdown documents, 'pages' are line numbers. Find nodes whose line_num falls within [min(page_nums), max(page_nums)] and return their text.

(doc_info: dict, page_nums: list[int])

Source from the content-addressed store, hash-verified

54
55
56def _get_md_page_content(doc_info: dict, page_nums: list[int]) -> list[dict]:
57 """
58 For Markdown documents, 'pages' are line numbers.
59 Find nodes whose line_num falls within [min(page_nums), max(page_nums)] and return their text.
60 """
61 min_line, max_line = min(page_nums), max(page_nums)
62 results = []
63 seen = set()
64
65 def _traverse(nodes):
66 for node in nodes:
67 ln = node.get('line_num')
68 if ln and min_line <= ln <= max_line and ln not in seen:
69 seen.add(ln)
70 results.append({'page': ln, 'content': node.get('text', '')})
71 if node.get('nodes'):
72 _traverse(node['nodes'])
73
74 _traverse(doc_info.get('structure', []))
75 results.sort(key=lambda x: x['page'])
76 return results
77
78
79# ── Tool functions ────────────────────────────────────────────────────────────

Callers 1

get_page_contentFunction · 0.85

Calls 1

_traverseFunction · 0.70

Tested by

no test coverage detected