MCPcopy Index your code
hub / github.com/codeaashu/claude-code / extractPathsFromText

Function extractPathsFromText

src/utils/claudemd.ts:458–491  ·  view source on GitHub ↗
(textContent: string)

Source from the content-addressed store, hash-verified

456
457 // Extract @paths from a text string and add resolved paths to absolutePaths.
458 function extractPathsFromText(textContent: string) {
459 const includeRegex = /(?:^|\s)@((?:[^\s\\]|\\ )+)/g
460 let match
461 while ((match = includeRegex.exec(textContent)) !== null) {
462 let path = match[1]
463 if (!path) continue
464
465 // Strip fragment identifiers (#heading, #section-name, etc.)
466 const hashIndex = path.indexOf('#')
467 if (hashIndex !== -1) {
468 path = path.substring(0, hashIndex)
469 }
470 if (!path) continue
471
472 // Unescape the spaces in the path
473 path = path.replace(/\\ /g, ' ')
474
475 // Accept @path, @./path, @~/path, or @/path
476 if (path) {
477 const isValidPath =
478 path.startsWith('./') ||
479 path.startsWith('~/') ||
480 (path.startsWith('/') && path !== '/') ||
481 (!path.startsWith('@') &&
482 !path.match(/^[#%^&*()]+/) &&
483 path.match(/^[a-zA-Z0-9._-]/))
484
485 if (isValidPath) {
486 const resolvedPath = expandPath(path, dirname(basePath))
487 absolutePaths.add(resolvedPath)
488 }
489 }
490 }
491 }
492
493 // Recursively process elements to find text nodes
494 function processElements(elements: MarkdownToken[]) {

Callers 1

processElementsFunction · 0.85

Calls 2

expandPathFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected