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