summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorKuuuube <61125188+Kuuuube@users.noreply.github.com>2024-02-08 06:54:30 -0500
committerGitHub <noreply@github.com>2024-02-08 11:54:30 +0000
commit3486c0a96c477d1d5ec66c947bb7e94b44c8554a (patch)
tree60cc89306c843f76431fbaa0597879adc1b2b9c9 /ext
parentd0eb43716b36bd770950485d806531628de9d277 (diff)
Add cloze-body-kana handlebar (#650)
* Add cloze-body-kana handlebar * Convert if else to ternary
Diffstat (limited to 'ext')
-rw-r--r--ext/data/templates/default-anki-field-templates.handlebars4
-rw-r--r--ext/js/data/anki-template-util.js1
-rw-r--r--ext/js/data/sandbox/anki-note-data-creator.js12
3 files changed, 16 insertions, 1 deletions
diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars
index 63613acf..2720b75b 100644
--- a/ext/data/templates/default-anki-field-templates.handlebars
+++ b/ext/data/templates/default-anki-field-templates.handlebars
@@ -160,6 +160,10 @@
{{~#if definition.cloze}}{{definition.cloze.body}}{{/if~}}
{{/inline}}
+{{#*inline "cloze-body-kana"}}
+ {{~#if definition.cloze}}{{definition.cloze.bodyKana}}{{/if~}}
+{{/inline}}
+
{{#*inline "cloze-suffix"}}
{{~#if definition.cloze}}{{definition.cloze.suffix}}{{/if~}}
{{/inline}}
diff --git a/ext/js/data/anki-template-util.js b/ext/js/data/anki-template-util.js
index 686b4af8..446c0c71 100644
--- a/ext/js/data/anki-template-util.js
+++ b/ext/js/data/anki-template-util.js
@@ -29,6 +29,7 @@ export function getStandardFieldMarkers(type) {
'clipboard-image',
'clipboard-text',
'cloze-body',
+ 'cloze-body-kana',
'cloze-prefix',
'cloze-suffix',
'conjugation',
diff --git a/ext/js/data/sandbox/anki-note-data-creator.js b/ext/js/data/sandbox/anki-note-data-creator.js
index f43595b6..d0456b0f 100644
--- a/ext/js/data/sandbox/anki-note-data-creator.js
+++ b/ext/js/data/sandbox/anki-note-data-creator.js
@@ -17,7 +17,7 @@
*/
import {getDisambiguations, getGroupedPronunciations, getPronunciationsOfType, getTermFrequency, groupTermTags} from '../../dictionary/dictionary-data-util.js';
-import {distributeFurigana} from '../../language/ja/japanese.js';
+import {distributeFurigana, distributeFuriganaInflected} from '../../language/ja/japanese.js';
/**
* Creates a compatibility representation of the specified data.
@@ -846,9 +846,13 @@ function convertPitchTag({name, category, content, order, score, dictionaries, r
*/
function getCloze(dictionaryEntry, context) {
let originalText = '';
+ let term = '';
+ let reading = '';
switch (dictionaryEntry.type) {
case 'term':
{
+ term = dictionaryEntry.headwords[0].term;
+ reading = dictionaryEntry.headwords[0].reading;
const primarySource = getPrimarySource(dictionaryEntry);
if (primarySource !== null) { originalText = primarySource.originalText; }
}
@@ -867,10 +871,16 @@ function getCloze(dictionaryEntry, context) {
if (typeof text !== 'string') { text = ''; }
if (typeof offset !== 'number') { offset = 0; }
+ const textSegments = [];
+ for (const {text: text2, reading: reading2} of distributeFuriganaInflected(term, reading, text.substring(offset, offset + originalText.length))) {
+ textSegments.push(reading2.length > 0 ? reading2 : text2);
+ }
+
return {
sentence: text,
prefix: text.substring(0, offset),
body: text.substring(offset, offset + originalText.length),
+ bodyKana: textSegments.join(''),
suffix: text.substring(offset + originalText.length)
};
}