diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-08-26 11:57:34 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-08-26 11:57:34 -0700 |
commit | 190c749527c5c5f8afec7ead6956a5f3d7c1a422 (patch) | |
tree | 2945b2c95657e71b1e99212d9646e6bd30961ab3 /ext/bg/js/handlebars.js | |
parent | 49f0243527e504aa3fe196bc6dc759b6948f8a0b (diff) |
improved furigana support
Diffstat (limited to 'ext/bg/js/handlebars.js')
-rw-r--r-- | ext/bg/js/handlebars.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js index a13de153..9cea14dc 100644 --- a/ext/bg/js/handlebars.js +++ b/ext/bg/js/handlebars.js @@ -26,6 +26,22 @@ function handlebarsDumpObject(options) { return handlebarsEscape(dump); } +function handlebarsFurigana(options) { + const definition = options.fn(this); + const segs = jpDistributeFurigana(definition.expression, definition.reading); + + let result = ''; + for (const seg of segs) { + if (seg.furigana) { + result += `<ruby>${seg.text}<rt>${seg.furigana}</rt></ruby>`; + } else { + result += seg.text; + } + } + + return result; +} + function handlebarsKanjiLinks(options) { let result = ''; for (const c of options.fn(this)) { @@ -47,6 +63,7 @@ function handlebarsRender(template, data) { if (Handlebars.partials !== Handlebars.templates) { Handlebars.partials = Handlebars.templates; Handlebars.registerHelper('dumpObject', handlebarsDumpObject); + Handlebars.registerHelper('furigana', handlebarsFurigana); Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks); Handlebars.registerHelper('multiLine', handlebarsMultiLine); } |