summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-05-29 15:00:19 -0700
committerAlex Yatskov <alex@foosoft.net>2016-05-29 15:00:19 -0700
commitc73641ec77398e93bccc85e5cda2b5c675d7e6e5 (patch)
tree5d0754df0fe44cb5e776f272c8ff2bc74ee43c32 /ext/bg/js
parent6f63999dce9f14103d6dfae155c4fc0c151ab8de (diff)
Better glossary formatting
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/yomichan.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index b3e8bf71..4120dd2b 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -146,7 +146,7 @@ class Yomichan {
}
}
- formatField(field, definition, kana) {
+ formatField(field, definition, mode) {
const supported = ['character', 'expression', 'glossary', 'kunyomi', 'onyomi', 'reading'];
for (const key in definition) {
@@ -155,18 +155,27 @@ class Yomichan {
}
let value = definition[key];
- if (kana) {
+ if (value !== null && typeof(value) !== 'string') {
+ value = value.join(', ');
+ }
+
+ if (mode === 'vocab_kana') {
if (key === 'expression') {
value = definition.reading;
} else if (key === 'reading') {
- value = '';
+ value = null;
}
}
- if (key === 'glossary') {
- value = definition.glossary.join('; ');
+
+ if (mode !== 'kanji' && key === 'glossary') {
+ value = '<ol>';
+ for (const gloss of definition.glossary) {
+ value += `<li>${gloss}</li>`;
+ }
+ value += '</ol>';
}
- field = field.replace(`{${key}}`, value);
+ field = field.replace(`{${key}}`, value || '');
}
return field;
@@ -187,7 +196,7 @@ class Yomichan {
}
for (const name in fields) {
- note.fields[name] = this.formatField(fields[name], definition, mode === 'vocab_kana');
+ note.fields[name] = this.formatField(fields[name], definition, mode);
}
return note;