MCPcopy Create free account
hub / github.com/OpenRaiser/NanoResearch / _split_sections

Function _split_sections

mcp_server/tools/pdf_reader.py:148–173  ·  view source on GitHub ↗

Split full text into sections based on heading patterns.

(text: str)

Source from the content-addressed store, hash-verified

146
147
148def _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

Callers 1

extract_text_from_bytesFunction · 0.85

Calls 2

matchMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected