aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/handlebars.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-08-26 12:18:35 -0700
committerAlex Yatskov <alex@foosoft.net>2017-08-26 12:18:35 -0700
commit18321ee4ed3e1254ebea5d81d1f99e4963595e8d (patch)
treebaba4d04e5da94546fc5cf10c7b9b69ba372bd4a /ext/bg/js/handlebars.js
parent190c749527c5c5f8afec7ead6956a5f3d7c1a422 (diff)
ankidroid furigana support
Diffstat (limited to 'ext/bg/js/handlebars.js')
-rw-r--r--ext/bg/js/handlebars.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js
index 9cea14dc..e0804986 100644
--- a/ext/bg/js/handlebars.js
+++ b/ext/bg/js/handlebars.js
@@ -42,6 +42,22 @@ function handlebarsFurigana(options) {
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)) {
@@ -64,6 +80,7 @@ function handlebarsRender(template, data) {
Handlebars.partials = Handlebars.templates;
Handlebars.registerHelper('dumpObject', handlebarsDumpObject);
Handlebars.registerHelper('furigana', handlebarsFurigana);
+ Handlebars.registerHelper('furiganaPlain', handlebarsFuriganaPlain);
Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks);
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
}