From 9577449e4bd2b7665e9161e50035393ef200205f Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Sat, 2 Mar 2024 06:28:09 -0500 Subject: Fix sentence-furigana template (#733) --- .../anki-field-templates-upgrade-v27.handlebars | 21 ++++++++++++++++ .../default-anki-field-templates.handlebars | 4 +-- ext/js/data/options-util.js | 19 +++++++++++--- test/options-util.test.js | 29 +++++++++++++++++++++- 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 ext/data/templates/anki-field-templates-upgrade-v27.handlebars diff --git a/ext/data/templates/anki-field-templates-upgrade-v27.handlebars b/ext/data/templates/anki-field-templates-upgrade-v27.handlebars new file mode 100644 index 00000000..67dca143 --- /dev/null +++ b/ext/data/templates/anki-field-templates-upgrade-v27.handlebars @@ -0,0 +1,21 @@ +{{<<<<<<<}} +{{#*inline "sentence-furigana"}} + {{~#if definition.cloze~}} + {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} + {{getMedia "textFurigana" definition.cloze.sentence escape=false}} + {{~else~}} + {{definition.cloze.sentence}} + {{~/if~}} + {{~/if~}} +{{/inline}} +{{=======}} +{{#*inline "sentence-furigana"}} + {{~#if definition.cloze~}} + {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} + {{{getMedia "textFurigana" definition.cloze.sentence escape=false}}} + {{~else~}} + {{{definition.cloze.sentence}}} + {{~/if~}} + {{~/if~}} +{{/inline}} +{{>>>>>>>}} diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 2720b75b..049cd56d 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -395,9 +395,9 @@ {{#*inline "sentence-furigana"}} {{~#if definition.cloze~}} {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} - {{getMedia "textFurigana" definition.cloze.sentence escape=false}} + {{{getMedia "textFurigana" definition.cloze.sentence escape=false}}} {{~else~}} - {{definition.cloze.sentence}} + {{{definition.cloze.sentence}}} {{~/if~}} {{~/if~}} {{/inline}} diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index f2d085fe..cac2f82d 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -532,7 +532,8 @@ export class OptionsUtil { this._updateVersion23, this._updateVersion24, this._updateVersion25, - this._updateVersion26 + this._updateVersion26, + this._updateVersion27 ]; /* eslint-enable @typescript-eslint/unbound-method */ if (typeof targetVersion === 'number' && targetVersion < result.length) { @@ -1156,9 +1157,11 @@ export class OptionsUtil { */ async _updateVersion25(options) { for (const profile of options.profiles) { - for (const hotkey of profile.options.inputs.hotkeys) { - if (hotkey.action === 'viewNote') { - hotkey.action = 'viewNotes'; + if ('inputs' in profile.options && 'hotkeys' in profile.options.inputs) { + for (const hotkey of profile.options.inputs.hotkeys) { + if (hotkey.action === 'viewNote') { + hotkey.action = 'viewNotes'; + } } } } @@ -1188,6 +1191,14 @@ export class OptionsUtil { } } + /** + * - Updated handlebars. + * @type {import('options-util').UpdateFunction} + */ + async _updateVersion27(options) { + await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v27.handlebars'); + } + /** * @param {string} url diff --git a/test/options-util.test.js b/test/options-util.test.js index 8c2bd775..9ccbd8ad 100644 --- a/test/options-util.test.js +++ b/test/options-util.test.js @@ -599,7 +599,7 @@ function createOptionsUpdatedTestData1() { } ], profileCurrent: 0, - version: 26, + version: 27, global: { database: { prefixWildcardsSupported: false @@ -1690,6 +1690,33 @@ describe('OptionsUtil', () => { {{~#*inline "pitch-accent-categories"~}} {{~#each (pitchCategories @root)~}}{{~.~}}{{~#unless @last~}},{{~/unless~}}{{~/each~}} {{~/inline~}}`.trimStart() + }, + { + oldVersion: 24, + newVersion: 27, + old: ` +{{#*inline "sentence-furigana"}} + {{~#if definition.cloze~}} + {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} + {{getMedia "textFurigana" definition.cloze.sentence escape=false}} + {{~else~}} + {{definition.cloze.sentence}} + {{~/if~}} + {{~/if~}} +{{/inline}} +`.trimStart(), + + expected: ` +{{#*inline "sentence-furigana"}} + {{~#if definition.cloze~}} + {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} + {{{getMedia "textFurigana" definition.cloze.sentence escape=false}}} + {{~else~}} + {{{definition.cloze.sentence}}} + {{~/if~}} + {{~/if~}} +{{/inline}} +`.trimStart() } ]; -- cgit v1.2.3