Fix furigana distribution when source/expression kana differs (#1532)

* Fix furigana distribution when source/expression kana differs

* Add an additional test
This commit is contained in:
toasted-nutbread 2021-03-15 23:02:38 -04:00 committed by GitHub
parent cba45b5e30
commit 8ae78449f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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) {

View File

@ -750,6 +750,19 @@ function testDistributeFuriganaInflected() {
[
{text: 'おこなわなかった', furigana: ''}
]
],
[
['いい', 'いい', 'イイ'],
[
{text: 'イイ', furigana: ''}
]
],
[
['否か', 'いなか', '否カ'],
[
{text: '否', furigana: 'いな'},
{text: 'カ', furigana: 'か'}
]
]
];