(body: string, ctx: TemplateContext)
| 157 | |
| 158 | /** Render a template body, resolving tokens and extracting the cursor offset. */ |
| 159 | export function renderTemplate(body: string, ctx: TemplateContext): RenderedTemplate { |
| 160 | const now = ctx.now ?? new Date() |
| 161 | const substituted = substituteTokens(body, ctx.title, now) |
| 162 | const cursorOffset = substituted.indexOf(CURSOR_TOKEN) |
| 163 | const finalBody = substituted.split(CURSOR_TOKEN).join('') |
| 164 | return { body: finalBody, cursorOffset: cursorOffset === -1 ? null : cursorOffset } |
| 165 | } |
| 166 | |
| 167 | /** Render a title pattern (e.g. `{{date:YYYY-MM-DD}} -- `). Cursor tokens drop. */ |
| 168 | export function renderTitle(titleTemplate: string, ctx: TemplateContext): string { |
no test coverage detected