Defer assignment of marker (#762)
This commit is contained in:
parent
3efd4a1a94
commit
21fc0a80f2
@ -81,9 +81,8 @@ class AnkiNoteBuilder {
|
||||
async formatField(field, data, templates, errors=null) {
|
||||
const pattern = /\{([\w-]+)\}/g;
|
||||
return await AnkiNoteBuilder.stringReplaceAsync(field, pattern, async (g0, marker) => {
|
||||
data.marker = marker;
|
||||
try {
|
||||
return await this._renderTemplate(templates, data);
|
||||
return await this._renderTemplate(templates, data, marker);
|
||||
} catch (e) {
|
||||
if (errors) { errors.push(e); }
|
||||
return `{${marker}-render-error}`;
|
||||
|
@ -518,8 +518,8 @@ class Backend {
|
||||
return await this._anki.guiBrowse(`nid:${noteId}`);
|
||||
}
|
||||
|
||||
async _onApiTemplateRender({template, data}) {
|
||||
return this._renderTemplate(template, data);
|
||||
async _onApiTemplateRender({template, data, marker}) {
|
||||
return this._renderTemplate(template, data, marker);
|
||||
}
|
||||
|
||||
_onApiCommandExec({command, params}) {
|
||||
@ -1339,8 +1339,8 @@ class Backend {
|
||||
return false;
|
||||
}
|
||||
|
||||
async _renderTemplate(template, data) {
|
||||
return await this._templateRenderer.render(template, data);
|
||||
async _renderTemplate(template, data, marker) {
|
||||
return await this._templateRenderer.render(template, data, marker);
|
||||
}
|
||||
|
||||
_getTemplates(options) {
|
||||
|
@ -28,7 +28,7 @@ class TemplateRenderer {
|
||||
this._stateStack = null;
|
||||
}
|
||||
|
||||
async render(template, data) {
|
||||
async render(template, data, marker) {
|
||||
if (!this._helpersRegistered) {
|
||||
this._registerHelpers();
|
||||
this._helpersRegistered = true;
|
||||
@ -42,11 +42,19 @@ class TemplateRenderer {
|
||||
cache.set(template, instance);
|
||||
}
|
||||
|
||||
const markerPre = data.marker;
|
||||
const markerPreHas = hasOwn(data, 'marker');
|
||||
try {
|
||||
this._stateStack = [new Map()];
|
||||
data.marker = marker;
|
||||
return instance(data).trim();
|
||||
} finally {
|
||||
this._stateStack = null;
|
||||
if (markerPreHas) {
|
||||
data.marker = markerPre;
|
||||
} else {
|
||||
delete data.marker;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,8 @@ const api = (() => {
|
||||
return this._invoke('noteView', {noteId});
|
||||
}
|
||||
|
||||
templateRender(template, data) {
|
||||
return this._invoke('templateRender', {data, template});
|
||||
templateRender(template, data, marker) {
|
||||
return this._invoke('templateRender', {data, template, marker});
|
||||
}
|
||||
|
||||
audioGetUri(definition, source, details) {
|
||||
|
Loading…
Reference in New Issue
Block a user