MCPcopy Create free account
hub / github.com/Noumena-Network/code / extractPathsFromText

Function extractPathsFromText

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

Source from the content-addressed store, hash-verified

560
561 // Extract @paths from a text string and add resolved paths to absolutePaths.
562 function extractPathsFromText(textContent: string) {
563 const includeRegex = /(?:^|\s)@((?:[^\s\\]|\\ )+)/g
564 let match
565 while ((match = includeRegex.exec(textContent)) !== null) {
566 let path = match[1]
567 if (!path) continue
568
569 // Strip fragment identifiers (#heading, #section-name, etc.)
570 const hashIndex = path.indexOf('#')
571 if (hashIndex !== -1) {
572 path = path.substring(0, hashIndex)
573 }
574 if (!path) continue
575
576 // Unescape the spaces in the path
577 path = path.replace(/\\ /g, ' ')
578
579 // Accept @path, @./path, @~/path, or @/path
580 if (path) {
581 const isValidPath =
582 path.startsWith('./') ||
583 path.startsWith('~/') ||
584 (path.startsWith('/') && path !== '/') ||
585 (!path.startsWith('@') &&
586 !path.match(/^[#%^&*()]+/) &&
587 path.match(/^[a-zA-Z0-9._-]/))
588
589 if (isValidPath) {
590 const resolvedPath = expandPath(path, dirname(basePath))
591 absolutePaths.add(resolvedPath)
592 }
593 }
594 }
595 }
596
597 // Recursively process elements to find text nodes
598 function processElements(elements: MarkdownToken[]) {

Callers 1

processElementsFunction · 0.85

Calls 2

expandPathFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected