(input: string, title: string, now: Date)
| 143 | } |
| 144 | |
| 145 | function substituteTokens(input: string, title: string, now: Date): string { |
| 146 | return input.replace(TOKEN_RE, (full, rawToken: string) => { |
| 147 | const token = rawToken.trim() |
| 148 | if (token === 'cursor') return CURSOR_TOKEN |
| 149 | if (token === 'title') return title |
| 150 | if (token === 'date') return formatISODate(now) |
| 151 | if (token === 'time') return formatTime(now) |
| 152 | if (token === 'week') return pad2(getISOWeek(now)) |
| 153 | if (token.startsWith('date:')) return formatDate(now, token.slice('date:'.length)) |
| 154 | return full // unknown token -> leave untouched |
| 155 | }) |
| 156 | } |
| 157 | |
| 158 | /** Render a template body, resolving tokens and extracting the cursor offset. */ |
| 159 | export function renderTemplate(body: string, ctx: TemplateContext): RenderedTemplate { |
no test coverage detected