diff options
Diffstat (limited to 'ext/js/templates')
-rw-r--r-- | ext/js/templates/anki-template-renderer.js | 17 | ||||
-rw-r--r-- | ext/js/templates/template-renderer-media-provider.js | 2 | ||||
-rw-r--r-- | ext/js/templates/template-renderer.js | 2 |
3 files changed, 15 insertions, 6 deletions
diff --git a/ext/js/templates/anki-template-renderer.js b/ext/js/templates/anki-template-renderer.js index ae3e7a36..888be9b0 100644 --- a/ext/js/templates/anki-template-renderer.js +++ b/ext/js/templates/anki-template-renderer.js @@ -659,12 +659,19 @@ export class AnkiTemplateRenderer { } /** + * @param {import('template-renderer').HelperOptions} options + * @returns {import('anki-templates').NoteData} + */ + _getNoteDataFromOptions(options) { + return options.data.root; + } + + /** * @type {import('template-renderer').HelperFunction<string>} */ _formatGlossary(args, _context, options) { const [dictionary, content] = /** @type {[dictionary: string, content: import('dictionary-data').TermGlossaryContent]} */ (args); - /** @type {import('anki-templates').NoteData} */ - const data = options.data.root; + const data = this._getNoteDataFromOptions(options); if (typeof content === 'string') { return this._safeString(this._stringToMultiLineHtml(content)); } if (!(typeof content === 'object' && content !== null)) { return ''; } switch (content.type) { @@ -703,8 +710,7 @@ export class AnkiTemplateRenderer { * @type {import('template-renderer').HelperFunction<boolean>} */ _hasMedia(args, _context, options) { - /** @type {import('anki-templates').NoteData} */ - const data = options.data.root; + const data = this._getNoteDataFromOptions(options); return this._mediaProvider.hasMedia(data, args, options.hash); } @@ -712,8 +718,7 @@ export class AnkiTemplateRenderer { * @type {import('template-renderer').HelperFunction<?string>} */ _getMedia(args, _context, options) { - /** @type {import('anki-templates').NoteData} */ - const data = options.data.root; + const data = this._getNoteDataFromOptions(options); return this._mediaProvider.getMedia(data, args, options.hash); } diff --git a/ext/js/templates/template-renderer-media-provider.js b/ext/js/templates/template-renderer-media-provider.js index 2f238e20..c4b07369 100644 --- a/ext/js/templates/template-renderer-media-provider.js +++ b/ext/js/templates/template-renderer-media-provider.js @@ -81,6 +81,8 @@ export class TemplateRendererMediaProvider { let {value} = data; const {escape = true} = namedArgs; if (escape) { + // Handlebars is a custom version of the library without type information, so it's assumed to be "any". + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment value = Handlebars.Utils.escapeExpression(value); } return value; diff --git a/ext/js/templates/template-renderer.js b/ext/js/templates/template-renderer.js index 7bb93aa2..c5b7cd63 100644 --- a/ext/js/templates/template-renderer.js +++ b/ext/js/templates/template-renderer.js @@ -117,6 +117,8 @@ export class TemplateRenderer { let instance = cache.get(template); if (typeof instance === 'undefined') { this._updateCacheSize(this._cacheMaxSize - 1); + // Handlebars is a custom version of the library without type information, so it's assumed to be "any". + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment instance = /** @type {import('handlebars').TemplateDelegate<import('anki-templates').NoteData>} */ (Handlebars.compileAST(template)); cache.set(template, instance); } |