summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/bg/js/options-form.js4
-rw-r--r--ext/bg/js/templates.js49
-rw-r--r--ext/bg/js/util.js62
-rw-r--r--ext/bg/js/yomichan.js8
-rw-r--r--tmpl/fields.html47
5 files changed, 120 insertions, 50 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js
index d3275926..84101ba0 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -342,8 +342,8 @@ function populateAnkiFields(element, options) {
}
const markers = {
- 'terms': ['audio', 'dictionary', 'expression', 'expression-furigana', 'glossary', 'glossary-list', 'reading', 'sentence', 'tags', 'url'],
- 'kanji': ['character', 'dictionary', 'glossary', 'glossary-list', 'kunyomi', 'onyomi', 'url']
+ 'terms': ['audio', 'dictionary', 'expression', 'furigana', 'glossary', 'reading', 'sentence', 'tags', 'url'],
+ 'kanji': ['character', 'dictionary', 'glossary', 'kunyomi', 'onyomi', 'url']
}[tabId] || {};
return anki().getModelFieldNames(modelName).then(names => {
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index a36e4674..500e0e55 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -25,6 +25,55 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p
+ alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
+ "\" class=\"form-control dict-priority\">\n </div>\n</div>\n";
},"useData":true});
+templates['fields.html'] = template({"1":function(container,depth0,helpers,partials,data) {
+ return "";
+},"3":function(container,depth0,helpers,partials,data) {
+ return "character\n";
+},"5":function(container,depth0,helpers,partials,data) {
+ return "dictionary\n";
+},"7":function(container,depth0,helpers,partials,data) {
+ return "expression\n";
+},"9":function(container,depth0,helpers,partials,data) {
+ return "furigana\n";
+},"11":function(container,depth0,helpers,partials,data) {
+ return "glossary\n";
+},"13":function(container,depth0,helpers,partials,data) {
+ return "kunyomi\n";
+},"15":function(container,depth0,helpers,partials,data) {
+ return "onyomi\n";
+},"17":function(container,depth0,helpers,partials,data) {
+ return "reading\n";
+},"19":function(container,depth0,helpers,partials,data) {
+ return "sentence\n";
+},"21":function(container,depth0,helpers,partials,data) {
+ return "tags\n";
+},"23":function(container,depth0,helpers,partials,data) {
+ return "url\n";
+},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) {
+ var stack1;
+
+ return "\n\n\n\n\n\n\n\n\n\n\n\n\n"
+ + ((stack1 = container.invokePartial(helpers.lookup.call(depth0 != null ? depth0 : {},depth0,"marker",{"name":"lookup","hash":{},"data":data}),depth0,{"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
+},"main_d": function(fn, props, container, depth0, data, blockParams, depths) {
+
+ var decorators = container.decorators;
+
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"args":["audio"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(3, data, 0, blockParams, depths),"inverse":container.noop,"args":["character"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(5, data, 0, blockParams, depths),"inverse":container.noop,"args":["dictionary"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(7, data, 0, blockParams, depths),"inverse":container.noop,"args":["expression"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(9, data, 0, blockParams, depths),"inverse":container.noop,"args":["furigana"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(11, data, 0, blockParams, depths),"inverse":container.noop,"args":["glossary"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(13, data, 0, blockParams, depths),"inverse":container.noop,"args":["kunyomi"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(15, data, 0, blockParams, depths),"inverse":container.noop,"args":["onyomi"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(17, data, 0, blockParams, depths),"inverse":container.noop,"args":["reading"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(19, data, 0, blockParams, depths),"inverse":container.noop,"args":["sentence"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(21, data, 0, blockParams, depths),"inverse":container.noop,"args":["tags"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(23, data, 0, blockParams, depths),"inverse":container.noop,"args":["url"],"data":data}) || fn;
+ return fn;
+ }
+
+,"useDecorators":true,"usePartial":true,"useData":true,"useDepths":true});
templates['kanji-list.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {};
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;
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 1f337680..820826f7 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -142,9 +142,15 @@ class Yomichan {
}
for (const name in fields) {
- note.fields[name] = formatField(fields[name], definition, mode);
+ note.fields[name] = formatField(
+ fields[name],
+ definition,
+ mode,
+ this.options.anki.htmlCards
+ );
}
+ console.log(note);
return note;
}
diff --git a/tmpl/fields.html b/tmpl/fields.html
new file mode 100644
index 00000000..6d3756d6
--- /dev/null
+++ b/tmpl/fields.html
@@ -0,0 +1,47 @@
+{{#*inline "audio"}}{{/inline}}
+
+{{#*inline "character"}}
+character
+{{/inline}}
+
+{{#*inline "dictionary"}}
+dictionary
+{{/inline}}
+
+{{#*inline "expression"}}
+expression
+{{/inline}}
+
+{{#*inline "furigana"}}
+furigana
+{{/inline}}
+
+{{#*inline "glossary"}}
+glossary
+{{/inline}}
+
+{{#*inline "kunyomi"}}
+kunyomi
+{{/inline}}
+
+{{#*inline "onyomi"}}
+onyomi
+{{/inline}}
+
+{{#*inline "reading"}}
+reading
+{{/inline}}
+
+{{#*inline "sentence"}}
+sentence
+{{/inline}}
+
+{{#*inline "tags"}}
+tags
+{{/inline}}
+
+{{#*inline "url"}}
+url
+{{/inline}}
+
+{{> (lookup . 'marker') }}