merged mode: Anki support

This commit is contained in:
siikamiika 2017-10-17 11:16:38 +03:00
parent 1edeabdaa8
commit 81f0a61651
3 changed files with 72 additions and 17 deletions

View File

@ -368,7 +368,8 @@ async function dictFieldFormat(field, definition, mode, options) {
merge: options.general.resultOutputMode === 'merge', merge: options.general.resultOutputMode === 'merge',
modeTermKanji: mode === 'term-kanji', modeTermKanji: mode === 'term-kanji',
modeTermKana: mode === 'term-kana', modeTermKana: mode === 'term-kana',
modeKanji: mode === 'kanji' modeKanji: mode === 'kanji',
compactGlossaries: options.general.compactGlossaries
}; };
const html = await apiTemplateRender(options.anki.fieldTemplates, data, true); const html = await apiTemplateRender(options.anki.fieldTemplates, data, true);

View File

@ -21,10 +21,15 @@ function optionsFieldTemplates() {
return ` return `
{{#*inline "glossary-single"}} {{#*inline "glossary-single"}}
{{~#unless brief~}} {{~#unless brief~}}
{{~#if tags~}}<i>({{#each tags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}})</i> {{/if~}} {{~#if definitionTags~}}<i>({{#each definitionTags}}{{name}}{{#unless @last}}, {{/unless}}{{/each}})</i> {{/if~}}
{{~#if only~}}({{#each only}}{{{.}}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
{{~/unless~}} {{~/unless~}}
{{~#if glossary.[1]~}} {{~#if glossary.[1]~}}
{{~#if compactGlossaries~}}
{{#each glossary}}{{#multiLine}}{{.}}{{/multiLine}}{{#unless @last}} | {{/unless}}{{/each}}
{{~else~}}
<ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul> <ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul>
{{~/if~}}
{{~else~}} {{~else~}}
{{~#multiLine}}{{glossary.[0]}}{{/multiLine~}} {{~#multiLine}}{{glossary.[0]}}{{/multiLine~}}
{{~/if~}} {{~/if~}}
@ -41,6 +46,24 @@ function optionsFieldTemplates() {
{{/inline}} {{/inline}}
{{#*inline "expression"}} {{#*inline "expression"}}
{{~#if merge~}}
{{~#if modeTermKana~}}
{{~#each definition.reading~}}
{{{.}}}
{{~#unless @last}}, {{/unless~}}
{{~else~}}
{{~#each definition.expression~}}
{{{.}}}
{{~#unless @last}}, {{/unless~}}
{{~/each~}}
{{~/each~}}
{{~else~}}
{{~#each definition.expression~}}
{{{.}}}
{{~#unless @last}}, {{/unless~}}
{{~/each~}}
{{~/if~}}
{{~else~}}
{{~#if modeTermKana~}} {{~#if modeTermKana~}}
{{~#if definition.reading~}} {{~#if definition.reading~}}
{{definition.reading}} {{definition.reading}}
@ -50,14 +73,29 @@ function optionsFieldTemplates() {
{{~else~}} {{~else~}}
{{definition.expression}} {{definition.expression}}
{{~/if~}} {{~/if~}}
{{~/if~}}
{{/inline}} {{/inline}}
{{#*inline "furigana"}} {{#*inline "furigana"}}
{{~#if merge~}}
{{~#each definition.expressions~}}
{{~#furigana}}{{{.}}}{{/furigana~}}
{{~#unless @last}}, {{/unless~}}
{{~/each~}}
{{~else~}}
{{#furigana}}{{{definition}}}{{/furigana}} {{#furigana}}{{{definition}}}{{/furigana}}
{{~/if~}}
{{/inline}} {{/inline}}
{{#*inline "furigana-plain"}} {{#*inline "furigana-plain"}}
{{~#if merge~}}
{{~#each definition.expressions~}}
{{~#furiganaPlain}}{{{.}}}{{/furiganaPlain~}}
{{~#unless @last}}, {{/unless~}}
{{~/each~}}
{{~else~}}
{{#furiganaPlain}}{{{definition}}}{{/furiganaPlain}} {{#furiganaPlain}}{{{definition}}}{{/furiganaPlain}}
{{~/if~}}
{{/inline}} {{/inline}}
{{#*inline "glossary"}} {{#*inline "glossary"}}
@ -71,12 +109,18 @@ function optionsFieldTemplates() {
{{~else~}} {{~else~}}
{{~#if group~}} {{~#if group~}}
{{~#if definition.definitions.[1]~}} {{~#if definition.definitions.[1]~}}
<ol>{{#each definition.definitions}}<li>{{> glossary-single brief=../brief}}</li>{{/each}}</ol> <ol>{{#each definition.definitions}}<li>{{> glossary-single brief=../brief compactGlossaries=../compactGlossaries}}</li>{{/each}}</ol>
{{~else~}} {{~else~}}
{{~> glossary-single definition.definitions.[0] brief=brief~}} {{~> glossary-single definition.definitions.[0] brief=brief compactGlossaries=compactGlossaries~}}
{{~/if~}}
{{~else if merge~}}
{{~#if definition.definitions.[1]~}}
<ol>{{#each definition.definitions}}<li>{{> glossary-single brief=../brief compactGlossaries=../compactGlossaries}}</li>{{/each}}</ol>
{{~else~}}
{{~> glossary-single definition.definitions.[0] brief=brief compactGlossaries=compactGlossaries~}}
{{~/if~}} {{~/if~}}
{{~else~}} {{~else~}}
{{~> glossary-single definition brief=brief~}} {{~> glossary-single definition brief=brief compactGlossaries=compactGlossaries~}}
{{~/if~}} {{~/if~}}
{{~/if~}} {{~/if~}}
</div> </div>
@ -95,7 +139,16 @@ function optionsFieldTemplates() {
{{/inline}} {{/inline}}
{{#*inline "reading"}} {{#*inline "reading"}}
{{~#unless modeTermKana}}{{definition.reading}}{{/unless~}} {{~#unless modeTermKana~}}
{{~#if merge~}}
{{~#each definition.reading~}}
{{{.}}}
{{~#unless @last}}, {{/unless~}}
{{~/each~}}
{{~else~}}
{{~definition.reading~}}
{{~/if~}}
{{~/unless~}}
{{/inline}} {{/inline}}
{{#*inline "sentence"}} {{#*inline "sentence"}}
@ -115,7 +168,7 @@ function optionsFieldTemplates() {
{{/inline}} {{/inline}}
{{#*inline "tags"}} {{#*inline "tags"}}
{{~#each definition.tags}}{{name}}{{#unless @last}}, {{/unless}}{{/each~}} {{~#each definition.definitionTags}}{{name}}{{#unless @last}}, {{/unless}}{{/each~}}
{{/inline}} {{/inline}}
{{#*inline "url"}} {{#*inline "url"}}

View File

@ -128,8 +128,9 @@ class Translator {
result.expressions = expressions; result.expressions = expressions;
// result.expression = Array.from(result.expression).join(', '); result.expression = Array.from(result.expression);
// result.reading = Array.from(result.reading).join(', '); result.reading = Array.from(result.reading);
definitionsMerged.push(result); definitionsMerged.push(result);
} }