summaryrefslogtreecommitdiff
path: root/ext/bg/js/anki-note-builder.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/anki-note-builder.js')
-rw-r--r--ext/bg/js/anki-note-builder.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js
index 7fe8962a..2405543e 100644
--- a/ext/bg/js/anki-note-builder.js
+++ b/ext/bg/js/anki-note-builder.js
@@ -15,6 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+/* global
+ * DictionaryDataUtil
+ */
+
class AnkiNoteBuilder {
constructor({anki, audioSystem, renderTemplate}) {
this._anki = anki;
@@ -39,9 +43,10 @@ class AnkiNoteBuilder {
}
};
+ const data = this.createNoteData(definition, mode, context, options);
const formattedFieldValuePromises = [];
for (const [, fieldValue] of modeOptionsFieldEntries) {
- const formattedFieldValuePromise = this.formatField(fieldValue, definition, mode, context, options, templates, null);
+ const formattedFieldValuePromise = this.formatField(fieldValue, data, templates, null);
formattedFieldValuePromises.push(formattedFieldValuePromise);
}
@@ -55,10 +60,14 @@ class AnkiNoteBuilder {
return note;
}
- async formatField(field, definition, mode, context, options, templates, errors=null) {
- const data = {
+ createNoteData(definition, mode, context, options) {
+ const pitches = DictionaryDataUtil.getPitchAccentInfos(definition);
+ const pitchCount = pitches.reduce((i, v) => i + v.pitches.length, 0);
+ return {
marker: null,
definition,
+ pitches,
+ pitchCount,
group: options.general.resultOutputMode === 'group',
merge: options.general.resultOutputMode === 'merge',
modeTermKanji: mode === 'term-kanji',
@@ -67,6 +76,9 @@ class AnkiNoteBuilder {
compactGlossaries: options.general.compactGlossaries,
context
};
+ }
+
+ async formatField(field, data, templates, errors=null) {
const pattern = /\{([\w-]+)\}/g;
return await AnkiNoteBuilder.stringReplaceAsync(field, pattern, async (g0, marker) => {
data.marker = marker;