(textContent: string)
| 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[]) { |
no test coverage detected