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

Function number_lines

explainshell/extraction/llm/text.py:180–193  ·  view source on GitHub ↗

Add line numbers to every line of text. Returns (numbered_text, original_lines) where original_lines is a dict mapping 1-indexed line numbers to their original content.

(text: str)

Source from the content-addressed store, hash-verified

178
179
180def number_lines(text: str) -> tuple[str, dict[int, str]]:
181 """Add line numbers to every line of text.
182
183 Returns (numbered_text, original_lines) where original_lines is a
184 dict mapping 1-indexed line numbers to their original content.
185 """
186 lines = text.split("\n")
187 original_lines: dict[int, str] = {}
188 numbered: list[str] = []
189 width = len(str(len(lines)))
190 for i, line in enumerate(lines, 1):
191 original_lines[i] = line
192 numbered.append(f"{i:>{width}}| {line}")
193 return "\n".join(numbered), original_lines
194
195
196def chunk_text(text: str) -> list[str]:

Callers 6

prepareMethod · 0.90
test_basicMethod · 0.90
test_single_lineMethod · 0.90
chunk_textFunction · 0.85

Calls

no outgoing calls

Tested by 4

test_basicMethod · 0.72
test_single_lineMethod · 0.72