From ae91e2442d7b3746c633871ff956a8addd7046b5 Mon Sep 17 00:00:00 2001 From: praschke Date: Tue, 17 Oct 2023 21:41:45 +0100 Subject: fix: furigana and furiganaPlain --- ext/data/templates/default-anki-field-templates.handlebars | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ext/data/templates/default-anki-field-templates.handlebars') diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 31d5d13f..751236f4 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -78,22 +78,22 @@ {{#*inline "furigana"}} {{~#if merge~}} {{~#each definition.expressions~}} - {{~#furigana}}{{{.}}}{{/furigana~}} + {{~furigana .~}} {{~#unless @last}}、{{/unless~}} {{~/each~}} {{~else~}} - {{#furigana}}{{{definition}}}{{/furigana}} + {{furigana definition}} {{~/if~}} {{/inline}} {{#*inline "furigana-plain"}} {{~#if merge~}} {{~#each definition.expressions~}} - {{~#furiganaPlain}}{{{.}}}{{/furiganaPlain~}} + {{~furiganaPlain .~}} {{~#unless @last}}、{{/unless~}} {{~/each~}} {{~else~}} - {{#furiganaPlain}}{{{definition}}}{{/furiganaPlain}} + {{furiganaPlain definition}} {{~/if~}} {{/inline}} @@ -255,7 +255,7 @@
  • {{~#if (op "!==" ../definition.type "kanji")~}} {{~#if (op "||" (op ">" ../uniqueExpressions.length 1) (op ">" ../uniqueReadings.length 1))~}}( - {{~#furigana expression reading~}}{{~/furigana~}} + {{~furigana expression reading~}} ) {{/if~}} {{~/if~}} {{~dictionary}}: {{frequency~}} -- cgit v1.2.3 From 376a1b096874e601296321fa6307836e2736a05c Mon Sep 17 00:00:00 2001 From: praschke Date: Tue, 17 Oct 2023 21:52:31 +0100 Subject: fix: formatGlossary --- docs/templates.md | 4 +- .../anki-field-templates-upgrade-v21.handlebars | 18 ++++++ .../default-anki-field-templates.handlebars | 6 +- ext/js/templates/sandbox/anki-template-renderer.js | 5 +- test/test-options-util.js | 74 ++++++++++++++++++++++ 5 files changed, 99 insertions(+), 8 deletions(-) (limited to 'ext/data/templates/default-anki-field-templates.handlebars') diff --git a/docs/templates.md b/docs/templates.md index bf5bd897..ce1e8d7e 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -657,7 +657,7 @@ structured-content generation.
    Syntax: - {{#formatGlossary dictionary}}{{{definitionEntry}}}{{/pitchCategories}}
    + {{formatGlossary dictionary definitionEntry}}
    * _`dictionary`_
    The dictionary that the glossary entry belongs to. @@ -668,7 +668,7 @@ structured-content generation. Example: ```handlebars - {{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{/each}} + {{#each glossary}}{{formatGlossary ../dictionary .}}{{/each}} ``` Output: diff --git a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars index 92034995..99db50b6 100644 --- a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars +++ b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars @@ -1,4 +1,22 @@ +{{<<<<<<<}} +{{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{/each}} +{{=======}} +{{#each glossary}}{{formatGlossary ../dictionary .}}{{/each}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{#unless @last}} | {{/unless}}{{/each}} +{{=======}} +{{#each glossary}}{{formatGlossary ../dictionary .}}{{#unless @last}} | {{/unless}}{{/each}} +{{>>>>>>>}} + +{{<<<<<<<}} +
      {{#each glossary}}
    • {{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}
    • {{/each}}
    +{{=======}} +
      {{#each glossary}}
    • {{formatGlossary ../dictionary .}}
    • {{/each}}
    +{{>>>>>>>}} + {{<<<<<<<}} {{~#furigana}}{{{.}}}{{/furigana~}} {{=======}} diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 751236f4..58bc68e2 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -21,11 +21,11 @@ {{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}} {{~/unless~}} {{~#if (op "<=" glossary.length 1)~}} - {{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{/each}} + {{#each glossary}}{{formatGlossary ../dictionary .}}{{/each}} {{~else if @root.compactGlossaries~}} - {{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{#unless @last}} | {{/unless}}{{/each}} + {{#each glossary}}{{formatGlossary ../dictionary .}}{{#unless @last}} | {{/unless}}{{/each}} {{~else~}} -
      {{#each glossary}}
    • {{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}
    • {{/each}}
    +
      {{#each glossary}}
    • {{formatGlossary ../dictionary .}}
    • {{/each}}
    {{~/if~}} {{~#set "previousDictionary" dictionary~}}{{~/set~}} {{/inline}} diff --git a/ext/js/templates/sandbox/anki-template-renderer.js b/ext/js/templates/sandbox/anki-template-renderer.js index e15bf895..62bf71b8 100644 --- a/ext/js/templates/sandbox/anki-template-renderer.js +++ b/ext/js/templates/sandbox/anki-template-renderer.js @@ -497,7 +497,7 @@ class AnkiTemplateRenderer { this._normalizeHtml(container, styleApplier, datasetKeyIgnorePattern); const result = container.innerHTML; container.textContent = ''; - return result; + return this._safeString(result); } _normalizeHtml(root, styleApplier, datasetKeyIgnorePattern) { @@ -550,9 +550,8 @@ class AnkiTemplateRenderer { return instance; } - _formatGlossary(context, dictionary, options) { + _formatGlossary(context, dictionary, content, options) { const data = options.data.root; - const content = options.fn(context); if (typeof content === 'string') { return this._stringToMultiLineHtml(this._escape(content)); } if (!(typeof content === 'object' && content !== null)) { return ''; } switch (content.type) { diff --git a/test/test-options-util.js b/test/test-options-util.js index e9504b0d..c2780650 100644 --- a/test/test-options-util.js +++ b/test/test-options-util.js @@ -1303,6 +1303,80 @@ async function testFieldTemplatesUpdate(extDir) { {{~/if~}} {{/inline}} +{{~> (lookup . "marker") ~}}`.trimStart() + }, + // block helper update: formatGlossary + { + oldVersion: 20, + newVersion: 21, + old: ` +{{#*inline "glossary-single"}} + {{~#unless brief~}} + {{~#scope~}} + {{~#set "any" false}}{{/set~}} + {{~#each definitionTags~}} + {{~#if (op "||" (op "!" @root.compactTags) (op "!" redundant))~}} + {{~#if (get "any")}}, {{else}}({{/if~}} + {{name}} + {{~#set "any" true}}{{/set~}} + {{~/if~}} + {{~/each~}} + {{~#unless noDictionaryTag~}} + {{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}} + {{~#if (get "any")}}, {{else}}({{/if~}} + {{dictionary}} + {{~#set "any" true}}{{/set~}} + {{~/if~}} + {{~/unless~}} + {{~#if (get "any")}}) {{/if~}} + {{~/scope~}} + {{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}} + {{~/unless~}} + {{~#if (op "<=" glossary.length 1)~}} + {{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{/each}} + {{~else if @root.compactGlossaries~}} + {{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{#unless @last}} | {{/unless}}{{/each}} + {{~else~}} +
      {{#each glossary}}
    • {{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}
    • {{/each}}
    + {{~/if~}} + {{~#set "previousDictionary" dictionary~}}{{~/set~}} +{{/inline}} + +{{~> (lookup . "marker") ~}}`.trimStart(), + + expected: ` +{{#*inline "glossary-single"}} + {{~#unless brief~}} + {{~#scope~}} + {{~#set "any" false}}{{/set~}} + {{~#each definitionTags~}} + {{~#if (op "||" (op "!" @root.compactTags) (op "!" redundant))~}} + {{~#if (get "any")}}, {{else}}({{/if~}} + {{name}} + {{~#set "any" true}}{{/set~}} + {{~/if~}} + {{~/each~}} + {{~#unless noDictionaryTag~}} + {{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}} + {{~#if (get "any")}}, {{else}}({{/if~}} + {{dictionary}} + {{~#set "any" true}}{{/set~}} + {{~/if~}} + {{~/unless~}} + {{~#if (get "any")}}) {{/if~}} + {{~/scope~}} + {{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}} + {{~/unless~}} + {{~#if (op "<=" glossary.length 1)~}} + {{#each glossary}}{{formatGlossary ../dictionary .}}{{/each}} + {{~else if @root.compactGlossaries~}} + {{#each glossary}}{{formatGlossary ../dictionary .}}{{#unless @last}} | {{/unless}}{{/each}} + {{~else~}} +
      {{#each glossary}}
    • {{formatGlossary ../dictionary .}}
    • {{/each}}
    + {{~/if~}} + {{~#set "previousDictionary" dictionary~}}{{~/set~}} +{{/inline}} + {{~> (lookup . "marker") ~}}`.trimStart() } ]; -- cgit v1.2.3 From 9f8269606fdf51765f6d13de4caac709691b0fea Mon Sep 17 00:00:00 2001 From: praschke Date: Tue, 17 Oct 2023 22:11:29 +0100 Subject: update: set and get --- docs/templates.md | 20 ++-- .../anki-field-templates-upgrade-v21.handlebars | 61 ++++++++++++ .../default-anki-field-templates.handlebars | 24 ++--- test/test-options-util.js | 110 ++++++++++++++++++++- 4 files changed, 189 insertions(+), 26 deletions(-) (limited to 'ext/data/templates/default-anki-field-templates.handlebars') diff --git a/docs/templates.md b/docs/templates.md index e0ea0861..e19309a7 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -351,7 +351,7 @@ Gets a value from the custom state stack.
    Syntax: - {{#get name}}{{/get}} + {{get name}} * _`name`_
    The name of the variable to get. @@ -360,7 +360,7 @@ Gets a value from the custom state stack. Example: ```handlebars - {{#get "some-text"}}{{/get}} + {{get "some-text"}} ``` Output: @@ -378,7 +378,7 @@ Assigns a value to the custom state stack. Syntax: {{#set name}}value{{/get}}
    - {{#set name value}}{{/get}}
    + {{set name value}}
    * _`name`_
    The name of the variable to assign. @@ -390,7 +390,7 @@ Assigns a value to the custom state stack. ```handlebars {{#set "some-text"}}This is the value of some-text!{{/set~}} - {{~#set "some-number" 32}}{{/set}} + {{~set "some-number" 32}} ``` Output: @@ -419,14 +419,14 @@ and variable lookups will start from the most recent scope and work backwards un Example: ```handlebars - {{~#set "key" 32}}{{/set~}} - {{~#get "key"}}{{/get~}}, + {{~set "key" 32~}} + {{~get "key"~}}, {{~#scope~}} - {{~#get "key"}}{{/get~}}, - {{~#set "key" 64}}{{/set~}} - {{~#get "key"}}{{/get~}}, + {{~#get "key"~}}, + {{~#set "key" 64~}} + {{~#get "key"~}}, {{~/scope~}} - {{~#get "key"}}{{/get~}} + {{~get "key"~}} ``` Output: diff --git a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars index 99db50b6..2fa0f0aa 100644 --- a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars +++ b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars @@ -1,3 +1,14 @@ +{{<<<<<<<}} +{{~#set "any" false}}{{/set~}} +{{=======}} +{{~set "any" false~}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{~#set "any" true}}{{/set~}} +{{=======}} +{{~set "any" true~}} +{{>>>>>>>}} {{<<<<<<<}} {{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{/each}} @@ -17,6 +28,12 @@
      {{#each glossary}}
    • {{formatGlossary ../dictionary .}}
    • {{/each}}
    {{>>>>>>>}} +{{<<<<<<<}} +{{~#set "previousDictionary" dictionary~}}{{~/set~}} +{{=======}} +{{~set "previousDictionary" dictionary~}} +{{>>>>>>>}} + {{<<<<<<<}} {{~#furigana}}{{{.}}}{{/furigana~}} {{=======}} @@ -46,3 +63,47 @@ {{=======}} {{~furigana expression reading~}} {{>>>>>>>}} + +{{<<<<<<<}} +{{~#set "exclusive" (spread exclusiveExpressions exclusiveReadings)}}{{/set~}} +{{=======}} +{{~set "exclusive" (spread exclusiveExpressions exclusiveReadings)~}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{~#set "separator" ""~}}{{/set~}} +{{=======}} +{{~set "separator" ""~}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{~#get "separator"}}{{/get~}}{{{.}}} +{{=======}} +{{~get "separator"~}}{{{.}}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{~#set "found" false}}{{/set~}} +{{=======}} +{{~set "found" false~}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{~#set "found" true}}{{/set~}} +{{=======}} +{{~set "found" true~}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{~#set "first" true}}{{/set~}} +{{=======}} +{{~set "first" true~}} +{{>>>>>>>}} + +{{<<<<<<<}} + {{~#set (concat "used_" .) true~}}{{~/set~}} + {{~#set "first" false~}}{{~/set~}} +{{=======}} + {{~set (concat "used_" .) true~}} + {{~set "first" false~}} +{{>>>>>>>}} diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 58bc68e2..69c7e7a1 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -1,19 +1,19 @@ {{#*inline "glossary-single"}} {{~#unless brief~}} {{~#scope~}} - {{~#set "any" false}}{{/set~}} + {{~set "any" false~}} {{~#each definitionTags~}} {{~#if (op "||" (op "!" @root.compactTags) (op "!" redundant))~}} {{~#if (get "any")}}, {{else}}({{/if~}} {{name}} - {{~#set "any" true}}{{/set~}} + {{~set "any" true~}} {{~/if~}} {{~/each~}} {{~#unless noDictionaryTag~}} {{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}} {{~#if (get "any")}}, {{else}}({{/if~}} {{dictionary}} - {{~#set "any" true}}{{/set~}} + {{~set "any" true~}} {{~/if~}} {{~/unless~}} {{~#if (get "any")}}) {{/if~}} @@ -27,7 +27,7 @@ {{~else~}}
      {{#each glossary}}
    • {{formatGlossary ../dictionary .}}
    • {{/each}}
    {{~/if~}} - {{~#set "previousDictionary" dictionary~}}{{~/set~}} + {{~set "previousDictionary" dictionary~}} {{/inline}} {{#*inline "audio"}} @@ -189,11 +189,11 @@ {{#*inline "pitch-accent-item-disambiguation"}} {{~#scope~}} - {{~#set "exclusive" (spread exclusiveExpressions exclusiveReadings)}}{{/set~}} + {{~set "exclusive" (spread exclusiveExpressions exclusiveReadings)~}} {{~#if (op ">" (property (get "exclusive") "length") 0)~}} - {{~#set "separator" ""~}}{{/set~}} + {{~set "separator" ""~}} ({{#each (get "exclusive")~}} - {{~#get "separator"}}{{/get~}}{{{.}}} + {{~get "separator"~}}{{{.}}} {{~/each}} only) {{~/if~}} {{~/scope~}} @@ -267,10 +267,10 @@ {{#*inline "stroke-count"}} {{~#scope~}} - {{~#set "found" false}}{{/set~}} + {{~set "found" false~}} {{~#each definition.stats.misc~}} {{~#if (op "===" name "strokes")~}} - {{~#set "found" true}}{{/set~}} + {{~set "found" true~}} Stroke count: {{value}} {{~/if~}} {{~/each~}} @@ -295,14 +295,14 @@ {{#*inline "part-of-speech"}} {{~#scope~}} {{~#if (op "!==" definition.type "kanji")~}} - {{~#set "first" true}}{{/set~}} + {{~set "first" true~}} {{~#each definition.expressions~}} {{~#each wordClasses~}} {{~#unless (get (concat "used_" .))~}} {{~> part-of-speech-pretty . ~}} {{~#unless (get "first")}}, {{/unless~}} - {{~#set (concat "used_" .) true~}}{{~/set~}} - {{~#set "first" false~}}{{~/set~}} + {{~set (concat "used_" .) true~}} + {{~set "first" false~}} {{~/unless~}} {{~/each~}} {{~/each~}} diff --git a/test/test-options-util.js b/test/test-options-util.js index c2780650..78204de9 100644 --- a/test/test-options-util.js +++ b/test/test-options-util.js @@ -1348,19 +1348,19 @@ async function testFieldTemplatesUpdate(extDir) { {{#*inline "glossary-single"}} {{~#unless brief~}} {{~#scope~}} - {{~#set "any" false}}{{/set~}} + {{~set "any" false~}} {{~#each definitionTags~}} {{~#if (op "||" (op "!" @root.compactTags) (op "!" redundant))~}} {{~#if (get "any")}}, {{else}}({{/if~}} {{name}} - {{~#set "any" true}}{{/set~}} + {{~set "any" true~}} {{~/if~}} {{~/each~}} {{~#unless noDictionaryTag~}} {{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}} {{~#if (get "any")}}, {{else}}({{/if~}} {{dictionary}} - {{~#set "any" true}}{{/set~}} + {{~set "any" true~}} {{~/if~}} {{~/unless~}} {{~#if (get "any")}}) {{/if~}} @@ -1374,7 +1374,109 @@ async function testFieldTemplatesUpdate(extDir) { {{~else~}}
      {{#each glossary}}
    • {{formatGlossary ../dictionary .}}
    • {{/each}}
    {{~/if~}} - {{~#set "previousDictionary" dictionary~}}{{~/set~}} + {{~set "previousDictionary" dictionary~}} +{{/inline}} + +{{~> (lookup . "marker") ~}}`.trimStart() + }, + // block helper update: set and get + { + oldVersion: 20, + newVersion: 21, + old: ` +{{#*inline "pitch-accent-item-disambiguation"}} + {{~#scope~}} + {{~#set "exclusive" (spread exclusiveExpressions exclusiveReadings)}}{{/set~}} + {{~#if (op ">" (property (get "exclusive") "length") 0)~}} + {{~#set "separator" ""~}}{{/set~}} + ({{#each (get "exclusive")~}} + {{~#get "separator"}}{{/get~}}{{{.}}} + {{~/each}} only) + {{~/if~}} + {{~/scope~}} +{{/inline}} + +{{#*inline "stroke-count"}} + {{~#scope~}} + {{~#set "found" false}}{{/set~}} + {{~#each definition.stats.misc~}} + {{~#if (op "===" name "strokes")~}} + {{~#set "found" true}}{{/set~}} + Stroke count: {{value}} + {{~/if~}} + {{~/each~}} + {{~#if (op "!" (get "found"))~}} + Stroke count: Unknown + {{~/if~}} + {{~/scope~}} +{{/inline}} + +{{#*inline "part-of-speech"}} + {{~#scope~}} + {{~#if (op "!==" definition.type "kanji")~}} + {{~#set "first" true}}{{/set~}} + {{~#each definition.expressions~}} + {{~#each wordClasses~}} + {{~#unless (get (concat "used_" .))~}} + {{~> part-of-speech-pretty . ~}} + {{~#unless (get "first")}}, {{/unless~}} + {{~#set (concat "used_" .) true~}}{{~/set~}} + {{~#set "first" false~}}{{~/set~}} + {{~/unless~}} + {{~/each~}} + {{~/each~}} + {{~#if (get "first")~}}Unknown{{~/if~}} + {{~/if~}} + {{~/scope~}} +{{/inline}} + +{{~> (lookup . "marker") ~}}`.trimStart(), + + expected: ` +{{#*inline "pitch-accent-item-disambiguation"}} + {{~#scope~}} + {{~set "exclusive" (spread exclusiveExpressions exclusiveReadings)~}} + {{~#if (op ">" (property (get "exclusive") "length") 0)~}} + {{~set "separator" ""~}} + ({{#each (get "exclusive")~}} + {{~get "separator"~}}{{{.}}} + {{~/each}} only) + {{~/if~}} + {{~/scope~}} +{{/inline}} + +{{#*inline "stroke-count"}} + {{~#scope~}} + {{~set "found" false~}} + {{~#each definition.stats.misc~}} + {{~#if (op "===" name "strokes")~}} + {{~set "found" true~}} + Stroke count: {{value}} + {{~/if~}} + {{~/each~}} + {{~#if (op "!" (get "found"))~}} + Stroke count: Unknown + {{~/if~}} + {{~/scope~}} +{{/inline}} + +{{#*inline "part-of-speech"}} + {{~#scope~}} + {{~#if (op "!==" definition.type "kanji")~}} + {{~set "first" true~}} + {{~#each definition.expressions~}} + {{~#each wordClasses~}} + {{~#unless (get (concat "used_" .))~}} + {{~> part-of-speech-pretty . ~}} + {{~#unless (get "first")}}, {{/unless~}} + {{~set (concat "used_" .) true~}} + {{~set "first" false~}} + {{~/unless~}} + {{~/each~}} + {{~/each~}} + {{~#if (get "first")~}}Unknown{{~/if~}} + {{~/if~}} + {{~/scope~}} {{/inline}} {{~> (lookup . "marker") ~}}`.trimStart() -- cgit v1.2.3 From 9b798601b48a40b65e38b433924a99d155872ba7 Mon Sep 17 00:00:00 2001 From: praschke Date: Tue, 17 Oct 2023 22:25:30 +0100 Subject: update: hasMedia and getMedia --- docs/templates.md | 18 ++--- .../anki-field-templates-upgrade-v21.handlebars | 36 ++++++++++ .../default-anki-field-templates.handlebars | 12 ++-- test/test-options-util.js | 82 ++++++++++++++++++++++ 4 files changed, 133 insertions(+), 15 deletions(-) (limited to 'ext/data/templates/default-anki-field-templates.handlebars') diff --git a/docs/templates.md b/docs/templates.md index e19309a7..0aa26b84 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -686,8 +686,8 @@ These functions are used together in order to request media and other types of o
    Syntax: - {{#hasMedia type args...}}{{/hasMedia}}
    - {{#getMedia type args... [escape=true|false]}}{{/getMedia}}
    + {{hasMedia type args...}}
    + {{getMedia type args... [escape=true|false]}}
    * _`type`_
    The type of media to check for. @@ -710,19 +710,19 @@ These functions are used together in order to request media and other types of o Examples: ```handlebars - {{#if (hasMedia "audio")}}The audio file name is: {{#getMedia "audio"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "audio")}}The audio file name is: {{getMedia "audio"}}{{/if}} - {{#if (hasMedia "screenshot")}}The screenshot file name is: {{#getMedia "screenshot"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "screenshot")}}The screenshot file name is: {{getMedia "screenshot"}}{{/if}} - {{#if (hasMedia "clipboardImage")}}The clipboard image file name is: {{#getMedia "clipboardImage"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "clipboardImage")}}The clipboard image file name is: {{getMedia "clipboardImage"}}{{/if}} - {{#if (hasMedia "clipboardText")}}The clipboard text is: {{#getMedia "clipboardText"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "clipboardText")}}The clipboard text is: {{getMedia "clipboardText"}}{{/if}} - {{#if (hasMedia "selectionText")}}The selection text is: {{#getMedia "selectionText"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "selectionText")}}The selection text is: {{getMedia "selectionText"}}{{/if}} - {{#if (hasMedia "textFurigana" "日本語")}}This is an example of text with generated furigana: {{#getMedia "textFurigana" "日本語" escape=false}}{{/getMedia}}{{/if}} + {{#if (hasMedia "textFurigana" "日本語")}}This is an example of text with generated furigana: {{getMedia "textFurigana" "日本語" escape=false}}{{/if}} - {{#if (hasMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary")}}The remapped file name for image.png is: {{#getMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary"}}{{/getMedia}}{{/if}} + {{#if (hasMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary")}}The remapped file name for image.png is: {{getMedia "dictionaryMedia" "image.png" dictionary="Example Dictionary"}}{{/if}} ``` Output: diff --git a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars index 2fa0f0aa..0bfd95a5 100644 --- a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars +++ b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars @@ -34,6 +34,12 @@ {{~set "previousDictionary" dictionary~}} {{>>>>>>>}} +{{<<<<<<<}} +[sound:{{#getMedia "audio"}}{{/getMedia}}] +{{=======}} +[sound:{{getMedia "audio"}}] +{{>>>>>>>}} + {{<<<<<<<}} {{~#furigana}}{{{.}}}{{/furigana~}} {{=======}} @@ -58,6 +64,24 @@ {{furiganaPlain definition}} {{>>>>>>>}} +{{<<<<<<<}} + +{{=======}} + +{{>>>>>>>}} + +{{<<<<<<<}} + +{{=======}} + +{{>>>>>>>}} + +{{<<<<<<<}} +{{~#if (hasMedia "clipboardText")}}{{#getMedia "clipboardText"}}{{/getMedia}}{{/if~}} +{{=======}} +{{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}} +{{>>>>>>>}} + {{<<<<<<<}} {{~#furigana expression reading~}}{{~/furigana~}} {{=======}} @@ -107,3 +131,15 @@ {{~set (concat "used_" .) true~}} {{~set "first" false~}} {{>>>>>>>}} + +{{<<<<<<<}} +{{~#if (hasMedia "selectionText")}}{{#getMedia "selectionText"}}{{/getMedia}}{{/if~}} +{{=======}} +{{~#if (hasMedia "selectionText")}}{{getMedia "selectionText"}}{{/if~}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{#getMedia "textFurigana" definition.cloze.sentence escape=false}}{{/getMedia}} +{{=======}} +{{getMedia "textFurigana" definition.cloze.sentence escape=false}} +{{>>>>>>>}} diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 69c7e7a1..08950f78 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -32,7 +32,7 @@ {{#*inline "audio"}} {{~#if (hasMedia "audio")~}} - [sound:{{#getMedia "audio"}}{{/getMedia}}] + [sound:{{getMedia "audio"}}] {{~/if~}} {{/inline}} @@ -174,7 +174,7 @@ {{#*inline "screenshot"}} {{~#if (hasMedia "screenshot")~}} - + {{~/if~}} {{/inline}} @@ -231,12 +231,12 @@ {{#*inline "clipboard-image"}} {{~#if (hasMedia "clipboardImage")~}} - + {{~/if~}} {{/inline}} {{#*inline "clipboard-text"}} - {{~#if (hasMedia "clipboardText")}}{{#getMedia "clipboardText"}}{{/getMedia}}{{/if~}} + {{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}} {{/inline}} {{#*inline "conjugation"}} @@ -316,13 +316,13 @@ {{/inline}} {{#*inline "selection-text"}} - {{~#if (hasMedia "selectionText")}}{{#getMedia "selectionText"}}{{/getMedia}}{{/if~}} + {{~#if (hasMedia "selectionText")}}{{getMedia "selectionText"}}{{/if~}} {{/inline}} {{#*inline "sentence-furigana"}} {{~#if definition.cloze~}} {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} - {{#getMedia "textFurigana" definition.cloze.sentence escape=false}}{{/getMedia}} + {{getMedia "textFurigana" definition.cloze.sentence escape=false}} {{~else~}} {{definition.cloze.sentence}} {{~/if~}} diff --git a/test/test-options-util.js b/test/test-options-util.js index 78204de9..23cfc121 100644 --- a/test/test-options-util.js +++ b/test/test-options-util.js @@ -1479,6 +1479,88 @@ async function testFieldTemplatesUpdate(extDir) { {{~/scope~}} {{/inline}} +{{~> (lookup . "marker") ~}}`.trimStart() + }, + // block helper update: hasMedia and getMedia + { + oldVersion: 20, + newVersion: 21, + old: ` +{{#*inline "audio"}} + {{~#if (hasMedia "audio")~}} + [sound:{{#getMedia "audio"}}{{/getMedia}}] + {{~/if~}} +{{/inline}} + +{{#*inline "screenshot"}} + {{~#if (hasMedia "screenshot")~}} + + {{~/if~}} +{{/inline}} + +{{#*inline "clipboard-image"}} + {{~#if (hasMedia "clipboardImage")~}} + + {{~/if~}} +{{/inline}} + +{{#*inline "clipboard-text"}} + {{~#if (hasMedia "clipboardText")}}{{#getMedia "clipboardText"}}{{/getMedia}}{{/if~}} +{{/inline}} + +{{#*inline "selection-text"}} + {{~#if (hasMedia "selectionText")}}{{#getMedia "selectionText"}}{{/getMedia}}{{/if~}} +{{/inline}} + +{{#*inline "sentence-furigana"}} + {{~#if definition.cloze~}} + {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} + {{#getMedia "textFurigana" definition.cloze.sentence escape=false}}{{/getMedia}} + {{~else~}} + {{definition.cloze.sentence}} + {{~/if~}} + {{~/if~}} +{{/inline}} + +{{~> (lookup . "marker") ~}}`.trimStart(), + + expected: ` +{{#*inline "audio"}} + {{~#if (hasMedia "audio")~}} + [sound:{{getMedia "audio"}}] + {{~/if~}} +{{/inline}} + +{{#*inline "screenshot"}} + {{~#if (hasMedia "screenshot")~}} + + {{~/if~}} +{{/inline}} + +{{#*inline "clipboard-image"}} + {{~#if (hasMedia "clipboardImage")~}} + + {{~/if~}} +{{/inline}} + +{{#*inline "clipboard-text"}} + {{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}} +{{/inline}} + +{{#*inline "selection-text"}} + {{~#if (hasMedia "selectionText")}}{{getMedia "selectionText"}}{{/if~}} +{{/inline}} + +{{#*inline "sentence-furigana"}} + {{~#if definition.cloze~}} + {{~#if (hasMedia "textFurigana" definition.cloze.sentence)~}} + {{getMedia "textFurigana" definition.cloze.sentence escape=false}} + {{~else~}} + {{definition.cloze.sentence}} + {{~/if~}} + {{~/if~}} +{{/inline}} + {{~> (lookup . "marker") ~}}`.trimStart() } ]; -- cgit v1.2.3 From 4527cc03fe88cd747d0eb62a65d9d54247653483 Mon Sep 17 00:00:00 2001 From: praschke Date: Tue, 17 Oct 2023 22:35:34 +0100 Subject: update: pronunciation --- docs/templates.md | 4 ++-- .../anki-field-templates-upgrade-v21.handlebars | 6 ++++++ .../templates/default-anki-field-templates.handlebars | 2 +- test/test-options-util.js | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) (limited to 'ext/data/templates/default-anki-field-templates.handlebars') diff --git a/docs/templates.md b/docs/templates.md index 0aa26b84..f021dea6 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -754,7 +754,7 @@ same as the system used for generating popup and search page dictionary entries.
    Syntax: - {{#pronunciation format=string reading=string downstepPosition=integer [nasalPositions=array] [devoicePositions=array]}}{{/pronunciation}}
    + {{pronunciation format=string reading=string downstepPosition=integer [nasalPositions=array] [devoicePositions=array]}}
    * _`format`_
    The format of the HTML to generate. This can be any of the following values: @@ -774,7 +774,7 @@ same as the system used for generating popup and search page dictionary entries. Example: ```handlebars - {{~#pronunciation format='text' reading='よむ' downstepPosition=1~}}{{~/pronunciation~}} + {{~pronunciation format='text' reading='よむ' downstepPosition=1~}} ```
    diff --git a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars index 0bfd95a5..4d88b812 100644 --- a/ext/data/templates/anki-field-templates-upgrade-v21.handlebars +++ b/ext/data/templates/anki-field-templates-upgrade-v21.handlebars @@ -82,6 +82,12 @@ {{~#if (hasMedia "clipboardText")}}{{getMedia "clipboardText"}}{{/if~}} {{>>>>>>>}} +{{<<<<<<<}} +{{~#pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}}{{~/pronunciation~}} +{{=======}} +{{~pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}} +{{>>>>>>>}} + {{<<<<<<<}} {{~#furigana expression reading~}}{{~/furigana~}} {{=======}} diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 08950f78..d94f6d70 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -184,7 +184,7 @@ {{! Pitch Accents }} {{#*inline "pitch-accent-item"}} - {{~#pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}}{{~/pronunciation~}} + {{~pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}} {{/inline}} {{#*inline "pitch-accent-item-disambiguation"}} diff --git a/test/test-options-util.js b/test/test-options-util.js index 23cfc121..d94028c0 100644 --- a/test/test-options-util.js +++ b/test/test-options-util.js @@ -1561,6 +1561,24 @@ async function testFieldTemplatesUpdate(extDir) { {{~/if~}} {{/inline}} +{{~> (lookup . "marker") ~}}`.trimStart() + }, + // block helper update: pronunciation + { + oldVersion: 20, + newVersion: 21, + old: ` +{{#*inline "pitch-accent-item"}} + {{~#pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}}{{~/pronunciation~}} +{{/inline}} + +{{~> (lookup . "marker") ~}}`.trimStart(), + + expected: ` +{{#*inline "pitch-accent-item"}} + {{~pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}} +{{/inline}} + {{~> (lookup . "marker") ~}}`.trimStart() } ]; -- cgit v1.2.3