diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-01-21 19:30:01 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-01-21 19:30:01 -0800 |
commit | 985c5df328ccff8492576d005a00fae828f56bab (patch) | |
tree | 79e14fff612e75c7f7ef6863e4843561fa5b6d45 /ext/bg/js/util.js | |
parent | 03e1a03634ed5bccea3bddb3f6487effc7eb17db (diff) |
WIP
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r-- | ext/bg/js/util.js | 62 |
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; |