work on sandbox

This commit is contained in:
Alex Yatskov 2017-09-06 13:35:18 -07:00
parent a3c8508031
commit 9efe7bfe1b
2 changed files with 9 additions and 6 deletions

View File

@ -62,7 +62,8 @@ async function apiDefinitionAdd(definition, mode) {
);
}
return utilBackend().anki.addNote(dictNoteFormat(definition, mode, options));
const note = await dictNoteFormat(definition, mode, options);
return utilBackend().anki.addNote(note);
}
async function apiDefinitionsAddable(definitions, modes) {
@ -72,7 +73,8 @@ async function apiDefinitionsAddable(definitions, modes) {
const notes = [];
for (const definition of definitions) {
for (const mode of modes) {
notes.push(dictNoteFormat(definition, mode, utilBackend().options));
const note = await dictNoteFormat(definition, mode, utilBackend().options);
notes.push(note);
}
}

View File

@ -192,7 +192,7 @@ function dictFieldSplit(field) {
return field.length === 0 ? [] : field.split(' ');
}
function dictFieldFormat(field, definition, mode, options) {
async function dictFieldFormat(field, definition, mode, options) {
const markers = [
'audio',
'character',
@ -223,13 +223,14 @@ function dictFieldFormat(field, definition, mode, options) {
modeKanji: mode === 'kanji'
};
field = field.replace(`{${marker}}`, handlebarsRender('fields.html', data));
const html = await apiTemplateRender(options.anki.fieldTemplates, data, true);
field = field.replace(`{${marker}}`, html);
}
return field;
}
function dictNoteFormat(definition, mode, options) {
async function dictNoteFormat(definition, mode, options) {
const note = {fields: {}, tags: options.anki.tags};
let fields = [];
@ -263,7 +264,7 @@ function dictNoteFormat(definition, mode, options) {
}
for (const name in fields) {
note.fields[name] = dictFieldFormat(fields[name], definition, mode, options);
note.fields[name] = await dictFieldFormat(fields[name], definition, mode, options);
}
return note;