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

Function parseCreateNotePath

packages/app-core/src/lib/wikilinks.ts:218–256  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

216}
217
218export function parseCreateNotePath(input: string): {
219 folder: NoteFolder
220 subpath: string
221 title: string
222 relPath: string
223} {
224 const normalized = normalizeSlashes(input.trim())
225 if (!normalized) throw new Error('Enter a note path.')
226 if (normalized === '/' || normalized === '.') throw new Error('Enter a note path.')
227
228 let folder: NoteFolder = 'inbox'
229 let rest = normalized
230
231 if (rest.startsWith('/')) {
232 rest = rest.replace(/^\/+/, '')
233 } else {
234 const top = rest.split('/')[0]?.toLowerCase()
235 if (top && TOP_FOLDERS.includes(top as NoteFolder)) {
236 folder = top as NoteFolder
237 rest = rest.split('/').slice(1).join('/')
238 }
239 }
240
241 rest = stripMdExtension(rest).replace(/\/+$/, '')
242 const parts = rest.split('/').filter(Boolean)
243 if (parts.length === 0) throw new Error('Enter a note path.')
244 if (parts.some((part) => part === '.' || part === '..')) {
245 throw new Error('Path cannot contain "." or "..".')
246 }
247 if (parts.some((part) => INVALID_NOTE_PATH_CHARS.test(part))) {
248 throw new Error('File names cannot contain # ^ [ ] \\ : * ? " < > |')
249 }
250
251 const title = parts[parts.length - 1].trim()
252 if (!title) throw new Error('Enter a note name.')
253 const subpath = parts.slice(0, -1).join('/')
254 const relPath = `${folder}/${subpath ? `${subpath}/` : ''}${title}.md`
255 return { folder, subpath, title, relPath }
256}
257
258export function stripMarkdownForMentions(body: string): string {
259 return stripCodeContent(body.replace(/^---\n[\s\S]*?\n---\n/, ' '))

Callers 4

handleCreateMissingLinkFunction · 0.90
registerVimCommandsFunction · 0.90
openOrCreateByPathFunction · 0.90
wikilinks.test.tsFile · 0.90

Calls 2

normalizeSlashesFunction · 0.70
stripMdExtensionFunction · 0.70

Tested by

no test coverage detected