MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / resolveInternalNoteHref

Function resolveInternalNoteHref

packages/app-core/src/lib/internal-links.ts:81–107  ·  view source on GitHub ↗
(
  notePath: string | null | undefined,
  href: string,
  notes: NoteRef[]
)

Source from the content-addressed store, hash-verified

79 * Returns null for external links, in-page anchors, assets, or no match.
80 */
81export 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
109function unwrapMdUrl(url: string): string {
110 // Markdown wraps URLs containing spaces in angle brackets: `[x](<a b.pdf>)`.

Callers 5

ConnectionsPanelFunction · 0.90
followEditorLinkFunction · 0.90
registerVimCommandsFunction · 0.90
onClickFunction · 0.90

Calls 5

isExternalHrefFunction · 0.85
decodeFunction · 0.85
matchNoteFunction · 0.85
posixJoinFunction · 0.70
posixNormalizeFunction · 0.70

Tested by

no test coverage detected