From 7cce3b9aebb6da75fb0ba0bfe15459aa47bbee00 Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Sat, 22 Jun 2024 00:40:59 -0400 Subject: Support dictionaryStylesMap in anki-deck-generator-controller and anki-templates-controller (#1112) * Support dictionaryStylesMap in bulk anki card generation * Move getDictionaryStylesMap to anki-note-builder * Support dictionaryStylesMap in anki-templates-controller * Strip newline to prevent tsv breaking * Allow dictionaryStylesMap to be omitted in createNote --------- Signed-off-by: Kuuuube <61125188+Kuuuube@users.noreply.github.com> --- ext/js/data/anki-note-builder.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'ext/js/data/anki-note-builder.js') diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js index 17bc1a5c..38588439 100644 --- a/ext/js/data/anki-note-builder.js +++ b/ext/js/data/anki-note-builder.js @@ -60,7 +60,7 @@ export class AnkiNoteBuilder { glossaryLayoutMode = 'default', compactTags = false, mediaOptions = null, - dictionaryStylesMap, + dictionaryStylesMap = new Map(), }) { let duplicateScopeDeckName = null; let duplicateScopeCheckChildren = false; @@ -173,6 +173,21 @@ export class AnkiNoteBuilder { return {type, term, reading}; } + /** + * @param {import('settings').DictionariesOptions} dictionaries + * @returns {Map} + */ + getDictionaryStylesMap(dictionaries) { + const styleMap = new Map(); + for (const dictionary of dictionaries) { + const {name, styles} = dictionary; + if (typeof styles === 'string') { + styleMap.set(name, styles); + } + } + return styleMap; + } + // Private /** -- cgit v1.2.3