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

Function suggestCreateNotePath

packages/app-core/src/lib/wikilinks.ts:201–216  ·  view source on GitHub ↗
(target: string)

Source from the content-addressed store, hash-verified

199}
200
201export function suggestCreateNotePath(target: string): string {
202 // Creating from `[[Doc#Heading]]` makes `Doc`, not the invalid `Doc#Heading`. (#196)
203 const trimmed = normalizeSlashes(stripWikilinkAnchor(target).trim()).replace(/\/+$/, '')
204 if (!trimmed) return '/Untitled.md'
205
206 if (trimmed.startsWith('/')) {
207 return /\.md$/i.test(trimmed) ? trimmed : `${stripMdExtension(trimmed)}.md`
208 }
209 if (TOP_FOLDERS.some((folder) => trimmed.toLowerCase().startsWith(`${folder}/`))) {
210 return /\.md$/i.test(trimmed) ? trimmed : `${stripMdExtension(trimmed)}.md`
211 }
212 if (trimmed.includes('/')) {
213 return `/${stripMdExtension(trimmed)}.md`
214 }
215 return `/${stripMdExtension(trimmed)}.md`
216}
217
218export function parseCreateNotePath(input: string): {
219 folder: NoteFolder

Callers 3

ConnectionsPanelFunction · 0.90
registerVimCommandsFunction · 0.90
wikilinks.test.tsFile · 0.90

Calls 3

stripWikilinkAnchorFunction · 0.85
normalizeSlashesFunction · 0.70
stripMdExtensionFunction · 0.70

Tested by

no test coverage detected