aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/options.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-11-12 20:34:11 -0500
committerGitHub <noreply@github.com>2020-11-12 20:34:11 -0500
commitec021964b7311d02fdbc5531564074f145043b91 (patch)
tree7d82366ed48e64c3dbad00e37a5f717134c59439 /ext/bg/js/options.js
parentf2ad94e54f2a110bf93aebfae33c808c497005be (diff)
Compact tags refactor (#1021)
* Update translator to flag redundant tags instead of remove * Update how compact tags are shown in the popup * Pass compactTags option to note builder * Update options templates * Add options upgrade * Add options upgrade test
Diffstat (limited to 'ext/bg/js/options.js')
-rw-r--r--ext/bg/js/options.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index bb90e655..e4f6c8e4 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -618,7 +618,35 @@ class OptionsUtil {
options.global.showPopupPreview = false;
for (const profile of options.profiles) {
profile.options.anki.checkForDuplicates = true;
+ const fieldTemplates = profile.options.anki.fieldTemplates;
+ if (typeof fieldTemplates === 'string') {
+ profile.options.anki.fieldTemplates = this._updateVersion6AnkiTemplatesCompactTags(fieldTemplates);
+ }
}
return options;
}
+
+ _updateVersion6AnkiTemplatesCompactTags(templates) {
+ const rawPattern1 = '{{~#if definitionTags~}}<i>({{#each definitionTags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}})</i> {{/if~}}';
+ const pattern1 = new RegExp(`((\r?\n)?[ \t]*)${escapeRegExp(rawPattern1)}`, 'g');
+ const replacement1 = (
+ // eslint-disable-next-line indent
+`{{~#scope~}}
+ {{~#set "any" false}}{{/set~}}
+ {{~#if definitionTags~}}{{#each definitionTags~}}
+ {{~#if (op "||" (op "!" ../data.compactTags) (op "!" redundant))~}}
+ {{~#if (get "any")}}, {{else}}<i>({{/if~}}
+ {{name}}
+ {{~#set "any" true}}{{/set~}}
+ {{~/if~}}
+ {{~/each~}}
+ {{~#if (get "any")}})</i> {{/if~}}
+ {{~/if~}}
+{{~/scope~}}`
+ );
+ const simpleNewline = /\n/g;
+ templates = templates.replace(pattern1, (g0, space) => (space + replacement1.replace(simpleNewline, space)));
+ templates = templates.replace(/\bcompactGlossaries=((?:\.*\/)*)compactGlossaries\b/g, (g0, g1) => `${g0} data=${g1}.`);
+ return templates;
+ }
}