aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js62
1 files changed, 15 insertions, 47 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index dcaf1e47..253fcd0f 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -201,15 +201,14 @@ function sortTags(tags) {
});
}
-function formatField(field, definition, mode) {
+function formatField(field, definition, mode, html) {
const markers = [
'audio',
'character',
'dictionary',
'expression',
- 'expression-furigana',
+ 'furigana',
'glossary',
- 'glossary-list',
'kunyomi',
'onyomi',
'reading',
@@ -219,50 +218,19 @@ function formatField(field, definition, mode) {
];
for (const marker of markers) {
- let value = definition[marker] || null;
- switch (marker) {
- case 'expression':
- if (mode === 'term_kana' && definition.reading) {
- value = definition.reading;
- }
- break;
- case 'expression-furigana':
- if (mode === 'term_kana' && definition.reading) {
- value = definition.reading;
- } else {
- value = `<ruby>${definition.expression}<rt>${definition.reading}</rt></ruby>`;
- }
- break;
- case 'reading':
- if (mode === 'term_kana') {
- value = null;
- }
- break;
- case 'glossary-list':
- if (definition.glossary) {
- if (definition.glossary.length > 1) {
- value = '<ol style="white-space: pre; text-align: left; overflow-x: auto;">';
- for (const gloss of definition.glossary) {
- value += `<li>${gloss}</li>`;
- }
- value += '</ol>';
- } else {
- value = `<p style="white-space: pre; overflow-x: auto;">${definition.glossary.join('')}</p>`;
- }
- }
- break;
- case 'tags':
- if (definition.tags) {
- value = definition.tags.map(t => t.name);
- }
- break;
- }
-
- if (value !== null && typeof(value) !== 'string') {
- value = value.join(', ');
- }
-
- field = field.replace(`{${marker}}`, value || '');
+ const data = {
+ marker,
+ definition,
+ html,
+ modeTermKanji: mode === 'term_kanji',
+ modeTermKana: mode === 'term_kana',
+ modeKanji: mode === 'kanji'
+ };
+
+ field = field.replace(
+ `{${marker}}`,
+ Handlebars.templates['fields.html'](data).trim()
+ );
}
return field;