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/pages/settings/anki-deck-generator-controller.js | 4 +++- ext/js/pages/settings/anki-templates-controller.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'ext/js/pages') diff --git a/ext/js/pages/settings/anki-deck-generator-controller.js b/ext/js/pages/settings/anki-deck-generator-controller.js index 70533223..1a65d80f 100644 --- a/ext/js/pages/settings/anki-deck-generator-controller.js +++ b/ext/js/pages/settings/anki-deck-generator-controller.js @@ -445,6 +445,7 @@ export class AnkiDeckGeneratorController { const idleTimeout = (Number.isFinite(options.anki.downloadTimeout) && options.anki.downloadTimeout > 0 ? options.anki.downloadTimeout : null); const mediaOptions = addMedia ? {audio: {sources: options.audio.sources, preferredAudioIndex: null, idleTimeout: idleTimeout}} : null; const requirements = addMedia ? [...this._getDictionaryEntryMedia(dictionaryEntry), {type: 'audio'}] : []; + const dictionaryStylesMap = this._ankiNoteBuilder.getDictionaryStylesMap(options.dictionaries); const {note} = await this._ankiNoteBuilder.createNote(/** @type {import('anki-note-builder').CreateNoteDetails} */ ({ dictionaryEntry, mode, @@ -461,6 +462,7 @@ export class AnkiDeckGeneratorController { requirements: requirements, duplicateScope: options.anki.duplicateScope, duplicateScopeCheckAllModels: options.anki.duplicateScopeCheckAllModels, + dictionaryStylesMap: dictionaryStylesMap, })); return note; } @@ -546,7 +548,7 @@ export class AnkiDeckGeneratorController { let tsv = ''; for (const key in noteFields) { if (Object.prototype.hasOwnProperty.call(noteFields, key)) { - tsv += noteFields[key].replaceAll('\t', '   ') + '\t'; + tsv += noteFields[key].replaceAll('\t', '   ').replaceAll('\n', '') + '\t'; } } return tsv; diff --git a/ext/js/pages/settings/anki-templates-controller.js b/ext/js/pages/settings/anki-templates-controller.js index 15566e75..af317881 100644 --- a/ext/js/pages/settings/anki-templates-controller.js +++ b/ext/js/pages/settings/anki-templates-controller.js @@ -278,7 +278,7 @@ export class AnkiTemplatesController { resultOutputMode, glossaryLayoutMode, compactTags, - dictionaryStylesMap: new Map(), + dictionaryStylesMap: this._ankiNoteBuilder.getDictionaryStylesMap(options.dictionaries), })); result = note.fields.field; allErrors.push(...errors); -- cgit v1.2.3