diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/js/data/anki-note-builder.js | 17 | ||||
-rw-r--r-- | ext/js/display/display-anki.js | 18 | ||||
-rw-r--r-- | ext/js/pages/settings/anki-deck-generator-controller.js | 4 | ||||
-rw-r--r-- | ext/js/pages/settings/anki-templates-controller.js | 2 |
4 files changed, 22 insertions, 19 deletions
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<string, string>} + */ + 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 /** diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js index 68a6654c..fc242549 100644 --- a/ext/js/display/display-anki.js +++ b/ext/js/display/display-anki.js @@ -149,7 +149,7 @@ export class DisplayAnki { glossaryLayoutMode: this._glossaryLayoutMode, compactTags: this._compactTags, marker: 'test', - dictionaryStylesMap: this._getDictionaryStylesMap(), + dictionaryStylesMap: this._ankiNoteBuilder.getDictionaryStylesMap(this._dictionaries), }); } catch (e) { ankiNoteDataException = e; @@ -813,7 +813,7 @@ export class DisplayAnki { const details = this._ankiNoteBuilder.getDictionaryEntryDetailsForNote(dictionaryEntry); const audioDetails = this._getAnkiNoteMediaAudioDetails(details); const optionsContext = this._display.getOptionsContext(); - const dictionaryStylesMap = this._getDictionaryStylesMap(); + const dictionaryStylesMap = this._ankiNoteBuilder.getDictionaryStylesMap(this._dictionaries); const {note, errors, requirements: outputRequirements} = await this._ankiNoteBuilder.createNote({ dictionaryEntry, @@ -848,20 +848,6 @@ export class DisplayAnki { } /** - * @returns {Map<string, string>} - */ - _getDictionaryStylesMap() { - const styleMap = new Map(); - for (const dictionary of this._dictionaries) { - const {name, styles} = dictionary; - if (typeof styles === 'string') { - styleMap.set(name, styles); - } - } - return styleMap; - } - - /** * @param {boolean} isTerms * @returns {import('display-anki').CreateMode[]} */ 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); |