This commit is contained in:
Alex Yatskov 2017-01-21 19:30:01 -08:00
parent 03e1a03634
commit 985c5df328
5 changed files with 119 additions and 49 deletions

View File

@ -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 => {

View File

@ -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 : {};

View File

@ -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;
}
const data = {
marker,
definition,
html,
modeTermKanji: mode === 'term_kanji',
modeTermKana: mode === 'term_kana',
modeKanji: mode === 'kanji'
};
if (value !== null && typeof(value) !== 'string') {
value = value.join(', ');
}
field = field.replace(`{${marker}}`, value || '');
field = field.replace(
`{${marker}}`,
Handlebars.templates['fields.html'](data).trim()
);
}
return field;

View File

@ -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;
}

47
tmpl/fields.html Normal file
View File

@ -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') }}