Conjugation marker (#988)

* Add {conjugation} marker

* Add info

* Add upgrade

* Update test
This commit is contained in:
toasted-nutbread 2020-11-04 20:39:23 -05:00 committed by GitHub
parent 255c8b724e
commit 5b9d709d40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 2 deletions

View File

@ -159,6 +159,7 @@ Flashcard fields can be configured with the following steps:
`{cloze-body}` | Raw, inflected term as it appeared before being reduced to dictionary form by Yomichan.
`{cloze-prefix}` | Fragment of the containing `{sentence}` starting at the beginning of `{sentence}` until the beginning of `{cloze-body}`.
`{cloze-suffix}` | Fragment of the containing `{sentence}` starting at the end of `{cloze-body}` until the end of `{sentence}`.
`{conjugation}` | Conjugation path from the raw inflected term to the source term.
`{dictionary}` | Name of the dictionary from which the card is being created (unavailable in *grouped* mode).
`{document-title}` | Title of the web page that the term appeared in.
`{expression}` | Term expressed as kanji (will be displayed in kana if kanji is not available).

View File

@ -0,0 +1,8 @@
{{#*inline "conjugation"}}
{{~#if definition.reasons~}}
{{~#each definition.reasons~}}
{{~#if (op ">" @index 0)}} « {{/if~}}
{{.}}
{{~/each~}}
{{~/if~}}
{{/inline}}

View File

@ -286,4 +286,13 @@
{{~#if definition.clipboardText~}}{{definition.clipboardText}}{{~/if~}}
{{/inline}}
{{#*inline "conjugation"}}
{{~#if definition.reasons~}}
{{~#each definition.reasons~}}
{{~#if (op ">" @index 0)}} « {{/if~}}
{{.}}
{{~/each~}}
{{~/if~}}
{{/inline}}
{{~> (lookup . "marker") ~}}

View File

@ -477,6 +477,10 @@ class OptionsUtil {
{
async: false,
update: this._updateVersion5.bind(this)
},
{
async: true,
update: this._updateVersion6.bind(this)
}
];
}
@ -604,4 +608,11 @@ class OptionsUtil {
}
return options;
}
async _updateVersion6(options) {
// Version 6 changes:
// Updated handlebars templates to include "conjugation" definition.
await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v6.handlebars');
return options;
}
}

View File

@ -79,6 +79,7 @@ class AnkiController {
'cloze-body',
'cloze-prefix',
'cloze-suffix',
'conjugation',
'dictionary',
'document-title',
'expression',

View File

@ -496,7 +496,7 @@ function createOptionsUpdatedTestData1() {
}
],
profileCurrent: 0,
version: 5,
version: 6,
global: {
database: {
prefixWildcardsSupported: false
@ -554,6 +554,7 @@ async function testFieldTemplatesUpdate(extDir) {
const loadDataFile = (fileName) => fs.readFileSync(path.join(extDir, fileName), {encoding: 'utf8'});
const update2 = loadDataFile('bg/data/anki-field-templates-upgrade-v2.handlebars');
const update4 = loadDataFile('bg/data/anki-field-templates-upgrade-v4.handlebars');
const update6 = loadDataFile('bg/data/anki-field-templates-upgrade-v6.handlebars');
const data = [
// Standard format
@ -572,6 +573,7 @@ async function testFieldTemplatesUpdate(extDir) {
${update2}
${update4}
${update6}
{{~> (lookup . "marker") ~}}`.trimStart()
},
// Non-standard marker format
@ -590,7 +592,8 @@ ${update4}
{{~> (lookup . "marker2") ~}}
${update2}
${update4}`.trimStart()
${update4}
${update6}`.trimStart()
},
// Empty test
{
@ -600,6 +603,7 @@ ${update4}`.trimStart()
expected: `
${update2}
${update4}
${update6}
{{~> (lookup . "marker") ~}}`.trimStart()
}
];