From 3486c0a96c477d1d5ec66c947bb7e94b44c8554a Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Thu, 8 Feb 2024 06:54:30 -0500 Subject: Add cloze-body-kana handlebar (#650) * Add cloze-body-kana handlebar * Convert if else to ternary --- ext/js/data/sandbox/anki-note-data-creator.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'ext/js/data/sandbox/anki-note-data-creator.js') 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) }; } -- cgit v1.2.3