summaryrefslogtreecommitdiff
path: root/ext/bg/js/handlebars.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-08-26 12:36:56 -0700
committerAlex Yatskov <alex@foosoft.net>2017-08-26 12:36:56 -0700
commit65b679caeb7ae7261ea6f2ba76d1b14ff1d68c5c (patch)
tree16ff39b4730b5c84b0952a0cdd10b09e86d6a5b3 /ext/bg/js/handlebars.js
parent4325f325975614dc728a14fec0478654b1b43777 (diff)
parentdbe6a16ca4db10b1c3ff51d0d79b563ff2bb7aeb (diff)
Merge branch 'master' into firefox-amo
Diffstat (limited to 'ext/bg/js/handlebars.js')
-rw-r--r--ext/bg/js/handlebars.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js
index a13de153..e0804986 100644
--- a/ext/bg/js/handlebars.js
+++ b/ext/bg/js/handlebars.js
@@ -26,6 +26,38 @@ 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 handlebarsFuriganaPlain(options) {
+ const definition = options.fn(this);
+ const segs = jpDistributeFurigana(definition.expression, definition.reading);
+
+ let result = '';
+ for (const seg of segs) {
+ if (seg.furigana) {
+ result += `${seg.text}[${seg.furigana}]`;
+ } else {
+ result += seg.text;
+ }
+ }
+
+ return result;
+}
+
function handlebarsKanjiLinks(options) {
let result = '';
for (const c of options.fn(this)) {
@@ -47,6 +79,8 @@ function handlebarsRender(template, data) {
if (Handlebars.partials !== Handlebars.templates) {
Handlebars.partials = Handlebars.templates;
Handlebars.registerHelper('dumpObject', handlebarsDumpObject);
+ Handlebars.registerHelper('furigana', handlebarsFurigana);
+ Handlebars.registerHelper('furiganaPlain', handlebarsFuriganaPlain);
Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks);
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
}