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

Function substituteTokens

packages/app-core/src/lib/template-render.ts:145–156  ·  view source on GitHub ↗
(input: string, title: string, now: Date)

Source from the content-addressed store, hash-verified

143}
144
145function 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. */
159export function renderTemplate(body: string, ctx: TemplateContext): RenderedTemplate {

Callers 2

renderTemplateFunction · 0.85
renderTitleFunction · 0.85

Calls 5

formatTimeFunction · 0.85
getISOWeekFunction · 0.85
formatISODateFunction · 0.70
pad2Function · 0.70
formatDateFunction · 0.70

Tested by

no test coverage detected