diff options
Diffstat (limited to 'ext/js')
-rw-r--r-- | ext/js/background/backend.js | 12 | ||||
-rw-r--r-- | ext/js/data/anki-note-data-creator.js | 6 | ||||
-rw-r--r-- | ext/js/display/display-generator.js | 6 | ||||
-rw-r--r-- | ext/js/language/japanese-util.js | 10 | ||||
-rw-r--r-- | ext/js/templates/template-renderer.js | 16 |
5 files changed, 27 insertions, 23 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 21b18e99..84ff2c0d 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -1066,9 +1066,9 @@ class Backend { const {headwords: [{term, reading}]} = dictionaryEntries[0]; const source = text.substring(i, i + originalTextLength); const textSegments = []; - for (const {text: text2, furigana} of jp.distributeFuriganaInflected(term, reading, source)) { - const reading2 = jp.convertReading(text2, furigana, readingMode); - textSegments.push({text: text2, reading: reading2}); + for (const {text: text2, reading: reading2} of jp.distributeFuriganaInflected(term, reading, source)) { + const reading3 = jp.convertReading(text2, reading2, readingMode); + textSegments.push({text: text2, reading: reading3}); } results.push(textSegments); i += originalTextLength; @@ -1102,13 +1102,13 @@ class Backend { for (const line of lines) { for (const {term, reading, source} of line) { const termParts = []; - for (const {text: text2, furigana} of jp.distributeFuriganaInflected( + for (const {text: text2, reading: reading2} of jp.distributeFuriganaInflected( term.length > 0 ? term : source, jp.convertKatakanaToHiragana(reading), source )) { - const reading2 = jp.convertReading(text2, furigana, readingMode); - termParts.push({text: text2, reading: reading2}); + const reading3 = jp.convertReading(text2, reading2, readingMode); + termParts.push({text: text2, reading: reading3}); } result.push(termParts); } diff --git a/ext/js/data/anki-note-data-creator.js b/ext/js/data/anki-note-data-creator.js index 1c32c4b4..e3ff2ca0 100644 --- a/ext/js/data/anki-note-data-creator.js +++ b/ext/js/data/anki-note-data-creator.js @@ -596,6 +596,10 @@ class AnkiNoteDataCreator { } _getTermHeadwordFuriganaSegments(term, reading) { - return this._japaneseUtil.distributeFurigana(term, reading); + const result = []; + for (const {text, reading: reading2} of this._japaneseUtil.distributeFurigana(term, reading)) { + result.push({text, furigana: reading2}); + } + return result; } } diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index 61c93b4a..9a90502e 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -715,13 +715,13 @@ class DisplayGenerator { _appendFurigana(container, term, reading, addText) { container.lang = 'ja'; const segments = this._japaneseUtil.distributeFurigana(term, reading); - for (const {text, furigana} of segments) { - if (furigana) { + for (const {text, reading: reading2} of segments) { + if (reading2) { const ruby = document.createElement('ruby'); const rt = document.createElement('rt'); addText(ruby, text); ruby.appendChild(rt); - rt.appendChild(document.createTextNode(furigana)); + rt.appendChild(document.createTextNode(reading2)); container.appendChild(ruby); } else { addText(container, text); diff --git a/ext/js/language/japanese-util.js b/ext/js/language/japanese-util.js index 4d5e8092..8780c24c 100644 --- a/ext/js/language/japanese-util.js +++ b/ext/js/language/japanese-util.js @@ -507,7 +507,7 @@ const JapaneseUtil = (() => { if (stemLength < source.length) { const remainder = source.substring(stemLength); const segmentCount = segments.length; - if (segmentCount > 0 && segments[segmentCount - 1].furigana.length === 0) { + if (segmentCount > 0 && segments[segmentCount - 1].reading.length === 0) { // Append to the last segment if it has an empty reading segments[segmentCount - 1].text += remainder; } else { @@ -554,8 +554,8 @@ const JapaneseUtil = (() => { // Private - _createFuriganaSegment(text, furigana) { - return {text, furigana}; + _createFuriganaSegment(text, reading) { + return {text, reading}; } _segmentizeFurigana(reading, readingNormalized, groups, groupsStart) { @@ -600,8 +600,8 @@ const JapaneseUtil = (() => { // More than one way to segmentize the tail; mark as ambiguous return null; } - const furigana = reading.substring(0, i); - segments.unshift(this._createFuriganaSegment(text, furigana)); + const segmentReading = reading.substring(0, i); + segments.unshift(this._createFuriganaSegment(text, segmentReading)); result = segments; } // There is only one way to segmentize the last non-kana group diff --git a/ext/js/templates/template-renderer.js b/ext/js/templates/template-renderer.js index ed9cc41c..9bb7a414 100644 --- a/ext/js/templates/template-renderer.js +++ b/ext/js/templates/template-renderer.js @@ -177,11 +177,11 @@ class TemplateRenderer { const segs = this._japaneseUtil.distributeFurigana(expression, reading); let result = ''; - for (const seg of segs) { - if (seg.furigana.length > 0) { - result += `<ruby>${seg.text}<rt>${seg.furigana}</rt></ruby>`; + for (const {text, reading: reading2} of segs) { + if (reading2.length > 0) { + result += `<ruby>${text}<rt>${reading2}</rt></ruby>`; } else { - result += seg.text; + result += text; } } @@ -193,12 +193,12 @@ class TemplateRenderer { const segs = this._japaneseUtil.distributeFurigana(expression, reading); let result = ''; - for (const seg of segs) { - if (seg.furigana.length > 0) { + for (const {text, reading: reading2} of segs) { + if (reading2.length > 0) { if (result.length > 0) { result += ' '; } - result += `${seg.text}[${seg.furigana}]`; + result += `${text}[${reading2}]`; } else { - result += seg.text; + result += text; } } |