aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/options.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-05-23 03:03:34 +0300
committerGitHub <noreply@github.com>2020-05-22 20:03:34 -0400
commit39df44eca40d00242d99e8121179ae8aeffce961 (patch)
treed7bbc8f6d1c30aa80526482b6aaad6e442adf85a /ext/bg/js/options.js
parent96ea941fa820a46c147bf9b494ab4710c69ecd9c (diff)
Fix "tags" template (#539)
* fix tag templates for merge and group modes * update version upgrade * adjust upgrade replacement order
Diffstat (limited to 'ext/bg/js/options.js')
-rw-r--r--ext/bg/js/options.js32
1 files changed, 22 insertions, 10 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 10df033c..35fdde82 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -111,19 +111,31 @@ const profileOptionsVersionUpdates = [
},
(options) => {
// Version 14 changes:
- // Changed template for Anki audio.
+ // Changed template for Anki audio and tags.
let fieldTemplates = options.anki.fieldTemplates;
if (typeof fieldTemplates !== 'string') { return; }
- const replacement = '{{#*inline "audio"}}\n {{~#if definition.audioFileName~}}\n [sound:{{definition.audioFileName}}]\n {{~/if~}}\n{{/inline}}';
- let replaced = false;
- fieldTemplates = fieldTemplates.replace(/\{\{#\*inline "audio"\}\}\{\{\/inline\}\}/g, () => {
- replaced = true;
- return replacement;
- });
-
- if (!replaced) {
- fieldTemplates += '\n\n' + replacement;
+ const replacements = [
+ [
+ '{{#*inline "audio"}}{{/inline}}',
+ '{{#*inline "audio"}}\n {{~#if definition.audioFileName~}}\n [sound:{{definition.audioFileName}}]\n {{~/if~}}\n{{/inline}}'
+ ],
+ [
+ '{{#*inline "tags"}}\n {{~#each definition.definitionTags}}{{name}}{{#unless @last}}, {{/unless}}{{/each~}}\n{{/inline}}',
+ '{{#*inline "tags"}}\n {{~#mergeTags definition group merge}}{{this}}{{/mergeTags~}}\n{{/inline}}'
+ ]
+ ];
+
+ for (const [pattern, replacement] of replacements) {
+ let replaced = false;
+ fieldTemplates = fieldTemplates.replace(new RegExp(escapeRegExp(pattern), 'g'), () => {
+ replaced = true;
+ return replacement;
+ });
+
+ if (!replaced) {
+ fieldTemplates += '\n\n' + replacement;
+ }
}
options.anki.fieldTemplates = fieldTemplates;