Audio support

This commit is contained in:
Alex Yatskov 2016-07-17 10:35:16 -07:00
parent f2bd0ec7bb
commit 09ec4af3c1
2 changed files with 21 additions and 1 deletions

View File

@ -152,6 +152,7 @@ class Yomichan {
formatField(field, definition, mode) { formatField(field, definition, mode) {
const tags = [ const tags = [
'audio',
'character', 'character',
'expression', 'expression',
'glossary', 'glossary',
@ -165,6 +166,9 @@ class Yomichan {
for (let tag of tags) { for (let tag of tags) {
let value = definition[tag] || null; let value = definition[tag] || null;
switch (tag) { switch (tag) {
case 'audio':
value = '';
break;
case 'expression': case 'expression':
if (mode === 'vocab_kana' && definition.reading) { if (mode === 'vocab_kana' && definition.reading) {
value = definition.reading; value = definition.reading;
@ -213,6 +217,22 @@ class Yomichan {
fields = this.options.ankiVocabFields; fields = this.options.ankiVocabFields;
note.deckName = this.options.ankiVocabDeck; note.deckName = this.options.ankiVocabDeck;
note.modelName = this.options.ankiVocabModel; note.modelName = this.options.ankiVocabModel;
const audio = {
kanji: definition.expression,
kana: definition.reading,
fields: []
};
for (let name in fields) {
if (fields[name].indexOf('{audio}') !== -1) {
audio.fields.push(name);
}
}
if (audio.fields.length > 0) {
note.audio = audio;
}
} }
for (let name in fields) { for (let name in fields) {

View File

@ -124,7 +124,7 @@
</tbody> </tbody>
</table> </table>
<p>Allowed tags: <code>{expression}</code>, <code>{reading}</code>, <code>{glossary}</code>, <code>{glossary-list}</code>, <code>{tags}</code></p> <p>Allowed tags: <code>{audio}</code>, <code>{expression}</code>, <code>{reading}</code>, <code>{glossary}</code>, <code>{glossary-list}</code>, <code>{tags}</code></p>
</div> </div>
<div id="kanji" class="tab-pane fade"> <div id="kanji" class="tab-pane fade">