summaryrefslogtreecommitdiff
path: root/ext/js/language/japanese-util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-15 23:02:38 -0400
committerGitHub <noreply@github.com>2021-03-15 23:02:38 -0400
commit8ae78449f205715d894efb34e786e947199ee28e (patch)
tree28a3939b7469a5e4ca49d301871090c9e9d74a3f /ext/js/language/japanese-util.js
parentcba45b5e304afe0623e1d032d65e5efc2fc3929b (diff)
Fix furigana distribution when source/expression kana differs (#1532)
* Fix furigana distribution when source/expression kana differs * Add an additional test
Diffstat (limited to 'ext/js/language/japanese-util.js')
-rw-r--r--ext/js/language/japanese-util.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/ext/js/language/japanese-util.js b/ext/js/language/japanese-util.js
index aa1e3f00..cade393b 100644
--- a/ext/js/language/japanese-util.js
+++ b/ext/js/language/japanese-util.js
@@ -475,13 +475,15 @@ const JapaneseUtil = (() => {
// Check if source is derived from the reading instead of the expression
const readingStemLength = this._getStemLength(readingNormalized, sourceNormalized);
- if (readingStemLength > stemLength) {
+ if (readingStemLength > 0 && readingStemLength >= stemLength) {
mainText = reading;
stemLength = readingStemLength;
+ reading = `${source.substring(0, stemLength)}${reading.substring(stemLength)}`;
}
const segments = [];
if (stemLength > 0) {
+ mainText = `${source.substring(0, stemLength)}${mainText.substring(stemLength)}`;
const segments2 = this.distributeFurigana(mainText, reading);
let consumed = 0;
for (const segment of segments2) {