summaryrefslogtreecommitdiff
path: root/ext/bg/js/anki-note-builder.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-12 22:47:07 -0500
committerGitHub <noreply@github.com>2021-01-12 22:47:07 -0500
commit5ae3acf6ff4d68379d9ea73c6ec90b8dfa69c6ad (patch)
treebb5ef5fd289b8f2fff8f4d276e432082bbf2bfe4 /ext/bg/js/anki-note-builder.js
parentb7c9fa105764eb2cd5befea86c98fe49f5763a1d (diff)
Anki note data abstraction (#1228)
* Create AnkiNoteData * Create AnkiNoteDataDefinitionProxyHandler * Update media injection * Create AnkiNoteDataDefinitionSecondaryProperties * Update note context format * Expose url and cloze on definition * Simplify for understandability * Remove unused _createNoteData * Update public object * Remove trims on sentence, since it should already be trimmed * Fix unused global
Diffstat (limited to 'ext/bg/js/anki-note-builder.js')
-rw-r--r--ext/bg/js/anki-note-builder.js42
1 files changed, 10 insertions, 32 deletions
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js
index 632d9f8a..eae5fbe4 100644
--- a/ext/bg/js/anki-note-builder.js
+++ b/ext/bg/js/anki-note-builder.js
@@ -16,7 +16,6 @@
*/
/* global
- * DictionaryDataUtil
* TemplateRendererProxy
*/
@@ -35,6 +34,7 @@ class AnkiNoteBuilder {
modelName,
fields,
tags=[],
+ injectedMedia=null,
checkForDuplicates=true,
duplicateScope='collection',
resultOutputMode='split',
@@ -50,7 +50,15 @@ class AnkiNoteBuilder {
duplicateScopeCheckChildren = true;
}
- const data = this._createNoteData(definition, mode, context, resultOutputMode, glossaryLayoutMode, compactTags);
+ const data = {
+ definition,
+ mode,
+ context,
+ resultOutputMode,
+ glossaryLayoutMode,
+ compactTags,
+ injectedMedia
+ };
const formattedFieldValuePromises = [];
for (const [, fieldValue] of fields) {
const formattedFieldValuePromise = this._formatField(fieldValue, data, templates, errors);
@@ -104,36 +112,6 @@ class AnkiNoteBuilder {
// Private
- _createNoteData(definition, mode, context, resultOutputMode, glossaryLayoutMode, compactTags) {
- const pitches = DictionaryDataUtil.getPitchAccentInfos(definition);
- const pitchCount = pitches.reduce((i, v) => i + v.pitches.length, 0);
- const uniqueExpressions = new Set();
- const uniqueReadings = new Set();
- if (definition.type !== 'kanji') {
- for (const {expression, reading} of definition.expressions) {
- uniqueExpressions.add(expression);
- uniqueReadings.add(reading);
- }
- }
- return {
- marker: null,
- definition,
- uniqueExpressions: [...uniqueExpressions],
- uniqueReadings: [...uniqueReadings],
- pitches,
- pitchCount,
- group: resultOutputMode === 'group',
- merge: resultOutputMode === 'merge',
- modeTermKanji: mode === 'term-kanji',
- modeTermKana: mode === 'term-kana',
- modeKanji: mode === 'kanji',
- compactGlossaries: (glossaryLayoutMode === 'compact'),
- glossaryLayoutMode,
- compactTags,
- context
- };
- }
-
async _formatField(field, data, templates, errors=null) {
return await this._stringReplaceAsync(field, this._markerPattern, async (g0, marker) => {
try {