summaryrefslogtreecommitdiff
path: root/ext/bg/js/anki-note-builder.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-01 16:23:33 -0400
committerGitHub <noreply@github.com>2020-08-01 16:23:33 -0400
commit838fd211c6737ce7e2b6802a43837cf4300b60d2 (patch)
tree24fb7fd7d8e6c494a3e51defc7f32a6c3aa73107 /ext/bg/js/anki-note-builder.js
parent1e839cd230e53f822478f945cb415a8af2b09aef (diff)
Pitch accent Anki field templates (#701)
* Template helper updates * Add pitch data to exported field formatting data * Reuse note data * Add no-op * Set up pitch accent templates * Refactor version update functions * Implement upgrade process for new Anki templates * Consistency * Update README and anki.js to have matching markers
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;