MCPcopy Create free account
hub / github.com/UNLINEARITY/Obsidian-CodeSpace / parseLineFragment

Function parseLineFragment

src/code_embed_markdown.ts:113–132  ·  view source on GitHub ↗
(hashPart: string)

Source from the content-addressed store, hash-verified

111}
112
113function parseLineFragment(hashPart: string): { startLine: number; endLine: number } | null {
114 if (!hashPart) {
115 return { startLine: 0, endLine: 0 };
116 }
117
118 const rangeMatch = hashPart.match(/^L?(\d+)-L?(\d+)$/i);
119 if (rangeMatch?.[1] && rangeMatch[2]) {
120 const startLine = Math.max(1, Number.parseInt(rangeMatch[1], 10));
121 const endLine = Math.max(startLine, Number.parseInt(rangeMatch[2], 10));
122 return { startLine, endLine };
123 }
124
125 const singleMatch = hashPart.match(/^L?(\d+)$/i);
126 if (singleMatch?.[1]) {
127 const startLine = Math.max(1, Number.parseInt(singleMatch[1], 10));
128 return { startLine, endLine: 0 };
129 }
130
131 return null;
132}
133
134function indentMultiline(text: string, indent: string): string {
135 if (!indent) return text;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected