aboutsummaryrefslogtreecommitdiff
path: root/ext/js/templates/anki-template-renderer.js
diff options
context:
space:
mode:
authorJames Maa <jmaa@berkeley.edu>2024-05-09 15:42:35 +0800
committerGitHub <noreply@github.com>2024-05-09 07:42:35 +0000
commit13278a5cf67de69678d8c4c5fb97e6eb00c94c11 (patch)
tree1d77bcf97bb9c6f08c88c9f80ea0da735d5721c2 /ext/js/templates/anki-template-renderer.js
parent77fa1d0f64b66d6e4fe9c8795c7844206edbcaf2 (diff)
Update eslint unsafe rule (#887)
* Enable @typescript-eslint/no-unsafe-assignment * Updates * Add missing import * Updates * Fix types? * Fix tests * Address comments * Move TextProcessorVariant to types * Update types/ext/translation-internal.d.ts Co-authored-by: StefanVukovic99 <stefanvukovic44@gmail.com> Signed-off-by: James Maa <jmaa@berkeley.edu> --------- Signed-off-by: James Maa <jmaa@berkeley.edu> Co-authored-by: toasted-nutbread <toasted-nutbread@users.noreply.github.com> Co-authored-by: StefanVukovic99 <stefanvukovic44@gmail.com>
Diffstat (limited to 'ext/js/templates/anki-template-renderer.js')
-rw-r--r--ext/js/templates/anki-template-renderer.js17
1 files changed, 11 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);
}