/**
 * Promptfoo renders the per-task canonical context (`contexts/canonical/<task>.md`)
 * through Nunjucks before passing it to the evaluated model. Doc payloads
 * routinely contain `{{ }}` from real templating languages (Vue, Liquid,
 * Mustache, Jinja, Nunjucks-in-Nunjucks examples) and Nunjucks parses
 * those at render time — without escaping, the run aborts with
 * `Template render error`.
 *
 * Every `DocFetcher` adapter must run its output through this escape
 * before writing it to disk; the escape is the same regardless of source
 * (Sanity Content Lake, Google Drive, future adapters) because the
 * consumer (Promptfoo) is the same.
 *
 * The function lives in eval rather than core because Promptfoo is an
 * eval-layer concern — the `DocFetcher` port abstraction in
 * `@sanity/ailf-core` has no concept of the templating engine its output
 * feeds.
 */
export function escapeNunjucks(text) {
    return text.replace(/\{\{|\}\}/g, (match) => match === "{{" ? '{{ "{{" }}' : '{{ "}}" }}');
}
