MCPcopy Index your code
hub / github.com/idank/explainshell / _split_sections

Function _split_sections

explainshell/extraction/llm/text.py:63–85  ·  view source on GitHub ↗

Split text into sections at markdown header lines (# or ##). Returns a list of (start_line, section_text) tuples where start_line is the 1-indexed line number of the first line in the section.

(text: str)

Source from the content-addressed store, hash-verified

61
62
63def _split_sections(text: str) -> list[tuple[int, str]]:
64 """Split text into sections at markdown header lines (# or ##).
65
66 Returns a list of (start_line, section_text) tuples where start_line
67 is the 1-indexed line number of the first line in the section.
68 """
69 lines = text.split("\n")
70 sections: list[tuple[int, str]] = []
71 current_start = 1
72 current_lines: list[str] = []
73
74 for i, line in enumerate(lines):
75 if re.match(r"^#{1,2} ", line) and current_lines:
76 sections.append((current_start, "\n".join(current_lines)))
77 current_start = i + 1
78 current_lines = [line]
79 else:
80 current_lines.append(line)
81
82 if current_lines:
83 sections.append((current_start, "\n".join(current_lines)))
84
85 return sections
86
87
88def clean_mandoc_artifacts(text: str) -> str:

Callers 3

filter_sectionsFunction · 0.85
_build_preambleFunction · 0.85
chunk_textFunction · 0.85

Calls 1

matchMethod · 0.80

Tested by

no test coverage detected