( notePath: string | null | undefined, href: string, notes: NoteRef[] )
| 79 | * Returns null for external links, in-page anchors, assets, or no match. |
| 80 | */ |
| 81 | export function resolveInternalNoteHref( |
| 82 | notePath: string | null | undefined, |
| 83 | href: string, |
| 84 | notes: NoteRef[] |
| 85 | ): InternalNoteLink | null { |
| 86 | if (!notePath) return null |
| 87 | const raw = href.trim() |
| 88 | if (!raw || isExternalHref(raw)) return null |
| 89 | |
| 90 | const hashIdx = raw.indexOf('#') |
| 91 | const rawPath = hashIdx >= 0 ? raw.slice(0, hashIdx) : raw |
| 92 | if (!rawPath) return null // pure "#heading" — same note, handled elsewhere |
| 93 | const heading = hashIdx >= 0 ? decode(raw.slice(hashIdx + 1)).trim() || null : null |
| 94 | |
| 95 | const decoded = decode(rawPath) |
| 96 | const noteDir = notePath.includes('/') ? notePath.slice(0, notePath.lastIndexOf('/')) : '' |
| 97 | let target = decoded.startsWith('/') |
| 98 | ? decoded.replace(/^\/+/, '') |
| 99 | : noteDir |
| 100 | ? posixJoin(noteDir, decoded) |
| 101 | : decoded |
| 102 | target = posixNormalize(target) |
| 103 | if (!target || target === '..' || target.startsWith('../')) return null |
| 104 | |
| 105 | const match = matchNote(notes, target) |
| 106 | return match ? { path: match, heading } : null |
| 107 | } |
| 108 | |
| 109 | function unwrapMdUrl(url: string): string { |
| 110 | // Markdown wraps URLs containing spaces in angle brackets: `[x](<a b.pdf>)`. |
no test coverage detected