summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/data/templates/anki-field-templates-upgrade-v33.handlebars69
-rw-r--r--ext/data/templates/default-anki-field-templates.handlebars14
-rw-r--r--ext/js/data/options-util.js10
-rw-r--r--test/options-util.test.js65
4 files changed, 149 insertions, 9 deletions
diff --git a/ext/data/templates/anki-field-templates-upgrade-v33.handlebars b/ext/data/templates/anki-field-templates-upgrade-v33.handlebars
new file mode 100644
index 00000000..6fb967e5
--- /dev/null
+++ b/ext/data/templates/anki-field-templates-upgrade-v33.handlebars
@@ -0,0 +1,69 @@
+{{<<<<<<<}}
+{{#*inline "sentence"}}
+ {{~#if definition.cloze}}{{definition.cloze.sentence}}{{/if~}}
+{{/inline}}
+{{=======}}
+{{#*inline "sentence"}}
+ {{~#if definition.cloze}}{{{definition.cloze.sentence}}}{{/if~}}
+{{/inline}}
+{{>>>>>>>}}
+
+{{<<<<<<<}}
+{{#*inline "cloze-prefix"}}
+ {{~#if definition.cloze}}{{definition.cloze.prefix}}{{/if~}}
+{{/inline}}
+{{=======}}
+{{#*inline "cloze-prefix"}}
+ {{~#if definition.cloze}}{{{definition.cloze.prefix}}}{{/if~}}
+{{/inline}}
+{{>>>>>>>}}
+
+{{<<<<<<<}}
+{{#*inline "cloze-body"}}
+ {{~#if definition.cloze}}{{definition.cloze.body}}{{/if~}}
+{{/inline}}
+{{=======}}
+{{#*inline "cloze-body"}}
+ {{~#if definition.cloze}}{{{definition.cloze.body}}}{{/if~}}
+{{/inline}}
+{{>>>>>>>}}
+
+{{<<<<<<<}}
+{{#*inline "cloze-body-kana"}}
+ {{~#if definition.cloze}}{{definition.cloze.bodyKana}}{{/if~}}
+{{/inline}}
+{{=======}}
+{{#*inline "cloze-body-kana"}}
+ {{~#if definition.cloze}}{{{definition.cloze.bodyKana}}}{{/if~}}
+{{/inline}}
+{{>>>>>>>}}
+
+{{<<<<<<<}}
+{{#*inline "cloze-suffix"}}
+ {{~#if definition.cloze}}{{definition.cloze.suffix}}{{/if~}}
+{{/inline}}
+{{=======}}
+{{#*inline "cloze-suffix"}}
+ {{~#if definition.cloze}}{{{definition.cloze.suffix}}}{{/if~}}
+{{/inline}}
+{{>>>>>>>}}
+
+{{<<<<<<<}}
+{{#*inline "clipboard-text"}}
+ {{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}}
+{{/inline}}
+{{=======}}
+{{#*inline "clipboard-text"}}
+ {{~#if (hasMedia "clipboardText")}}{{{getMedia "clipboardText"}}}{{/if~}}
+{{/inline}}
+{{>>>>>>>}}
+
+{{<<<<<<<}}
+{{#*inline "selection-text"}}
+ {{~#if (hasMedia "selectionText")}}{{getMedia "selectionText"}}{{/if~}}
+{{/inline}}
+{{=======}}
+{{#*inline "selection-text"}}
+ {{~#if (hasMedia "selectionText")}}{{{getMedia "selectionText"}}}{{/if~}}
+{{/inline}}
+{{>>>>>>>}} \ No newline at end of file
diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars
index 46d5c889..3ca7ba18 100644
--- a/ext/data/templates/default-anki-field-templates.handlebars
+++ b/ext/data/templates/default-anki-field-templates.handlebars
@@ -149,23 +149,23 @@
{{/inline}}
{{#*inline "sentence"}}
- {{~#if definition.cloze}}{{definition.cloze.sentence}}{{/if~}}
+ {{~#if definition.cloze}}{{{definition.cloze.sentence}}}{{/if~}}
{{/inline}}
{{#*inline "cloze-prefix"}}
- {{~#if definition.cloze}}{{definition.cloze.prefix}}{{/if~}}
+ {{~#if definition.cloze}}{{{definition.cloze.prefix}}}{{/if~}}
{{/inline}}
{{#*inline "cloze-body"}}
- {{~#if definition.cloze}}{{definition.cloze.body}}{{/if~}}
+ {{~#if definition.cloze}}{{{definition.cloze.body}}}{{/if~}}
{{/inline}}
{{#*inline "cloze-body-kana"}}
- {{~#if definition.cloze}}{{definition.cloze.bodyKana}}{{/if~}}
+ {{~#if definition.cloze}}{{{definition.cloze.bodyKana}}}{{/if~}}
{{/inline}}
{{#*inline "cloze-suffix"}}
- {{~#if definition.cloze}}{{definition.cloze.suffix}}{{/if~}}
+ {{~#if definition.cloze}}{{{definition.cloze.suffix}}}{{/if~}}
{{/inline}}
{{#*inline "tags"}}
@@ -269,7 +269,7 @@
{{/inline}}
{{#*inline "clipboard-text"}}
- {{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}}
+ {{~#if (hasMedia "clipboardText")}}{{{getMedia "clipboardText"}}}{{/if~}}
{{/inline}}
{{#*inline "conjugation"}}
@@ -393,7 +393,7 @@
{{/inline}}
{{#*inline "selection-text"}}
- {{~#if (hasMedia "selectionText")}}{{getMedia "selectionText"}}{{/if~}}
+ {{~#if (hasMedia "selectionText")}}{{{getMedia "selectionText"}}}{{/if~}}
{{/inline}}
{{#*inline "sentence-furigana"}}
diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js
index 5319cfe4..d6c667aa 100644
--- a/ext/js/data/options-util.js
+++ b/ext/js/data/options-util.js
@@ -538,7 +538,8 @@ export class OptionsUtil {
this._updateVersion29,
this._updateVersion30,
this._updateVersion31,
- this._updateVersion32
+ this._updateVersion32,
+ this._updateVersion33
];
/* eslint-enable @typescript-eslint/unbound-method */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
@@ -1258,6 +1259,13 @@ export class OptionsUtil {
}
}
+ /**
+ * - Updated handlebars to fix escaping when using `definition.cloze` or text-based `getMedia`.
+ * @type {import('options-util').UpdateFunction}
+ */
+ async _updateVersion33(options) {
+ await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v33.handlebars');
+ }
/**
* @param {string} url
diff --git a/test/options-util.test.js b/test/options-util.test.js
index 0966d0d3..f44dbb4f 100644
--- a/test/options-util.test.js
+++ b/test/options-util.test.js
@@ -605,7 +605,7 @@ function createOptionsUpdatedTestData1() {
}
],
profileCurrent: 0,
- version: 32,
+ version: 33,
global: {
database: {
prefixWildcardsSupported: false
@@ -1723,6 +1723,69 @@ describe('OptionsUtil', () => {
{{~/if~}}
{{/inline}}
`.trimStart()
+ },
+ {
+ oldVersion: 32,
+ newVersion: 33,
+ old: `
+{{#*inline "sentence"}}
+ {{~#if definition.cloze}}{{definition.cloze.sentence}}{{/if~}}
+{{/inline}}
+
+{{#*inline "cloze-prefix"}}
+ {{~#if definition.cloze}}{{definition.cloze.prefix}}{{/if~}}
+{{/inline}}
+
+{{#*inline "cloze-body"}}
+ {{~#if definition.cloze}}{{definition.cloze.body}}{{/if~}}
+{{/inline}}
+
+{{#*inline "cloze-body-kana"}}
+ {{~#if definition.cloze}}{{definition.cloze.bodyKana}}{{/if~}}
+{{/inline}}
+
+{{#*inline "cloze-suffix"}}
+ {{~#if definition.cloze}}{{definition.cloze.suffix}}{{/if~}}
+{{/inline}}
+
+{{#*inline "clipboard-text"}}
+ {{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}}
+{{/inline}}
+
+{{#*inline "selection-text"}}
+ {{~#if (hasMedia "selectionText")}}{{getMedia "selectionText"}}{{/if~}}
+{{/inline}}
+`.trimStart(),
+
+ expected: `
+{{#*inline "sentence"}}
+ {{~#if definition.cloze}}{{{definition.cloze.sentence}}}{{/if~}}
+{{/inline}}
+
+{{#*inline "cloze-prefix"}}
+ {{~#if definition.cloze}}{{{definition.cloze.prefix}}}{{/if~}}
+{{/inline}}
+
+{{#*inline "cloze-body"}}
+ {{~#if definition.cloze}}{{{definition.cloze.body}}}{{/if~}}
+{{/inline}}
+
+{{#*inline "cloze-body-kana"}}
+ {{~#if definition.cloze}}{{{definition.cloze.bodyKana}}}{{/if~}}
+{{/inline}}
+
+{{#*inline "cloze-suffix"}}
+ {{~#if definition.cloze}}{{{definition.cloze.suffix}}}{{/if~}}
+{{/inline}}
+
+{{#*inline "clipboard-text"}}
+ {{~#if (hasMedia "clipboardText")}}{{{getMedia "clipboardText"}}}{{/if~}}
+{{/inline}}
+
+{{#*inline "selection-text"}}
+ {{~#if (hasMedia "selectionText")}}{{{getMedia "selectionText"}}}{{/if~}}
+{{/inline}}
+`.trimStart()
}
];