Extract just the three keys we care about. Unparseable lines are ignored.
(body: string)
| 103 | |
| 104 | /** Extract just the three keys we care about. Unparseable lines are ignored. */ |
| 105 | function parseNoteDefaults(body: string): { defaults: NoteDefaults; fmEndOffset: number } { |
| 106 | const m = body.match(FRONTMATTER_RE) |
| 107 | if (!m) return { defaults: {}, fmEndOffset: 0 } |
| 108 | const block = m[1] |
| 109 | const defaults: NoteDefaults = {} |
| 110 | for (const rawLine of block.split('\n')) { |
| 111 | const line = rawLine.trim() |
| 112 | if (!line || line.startsWith('#')) continue |
| 113 | const colon = line.indexOf(':') |
| 114 | if (colon < 1) continue |
| 115 | const key = line.slice(0, colon).trim().toLowerCase() |
| 116 | const value = unquote(line.slice(colon + 1)) |
| 117 | if (key === 'due') { |
| 118 | const d = normalizeDueDate(value) |
| 119 | if (d) defaults.due = d |
| 120 | } else if (key === 'priority') { |
| 121 | const p = normalizePriority(value) |
| 122 | if (p) defaults.priority = p |
| 123 | } else if (key === 'status') { |
| 124 | defaults.status = value.toLowerCase() |
| 125 | } |
| 126 | } |
| 127 | return { defaults, fmEndOffset: m[0].length } |
| 128 | } |
| 129 | |
| 130 | // --------------------------------------------------------------------------- |
| 131 | // Inline token extraction |
no test coverage detected