Skip to content

Commit 238cc8a

Browse files
fix(handleCJK): improve CJK character handling and word replacement
1 parent 12f0a18 commit 238cc8a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class SplitText {
8686
element.style.removeProperty('width');
8787
this.attachBr(element, this.words);
8888
this.splitBr(element);
89-
this.replaceWords(element);
89+
this.replaceWords(element, (byLines || byWords) && !byChars);
9090
this.lines.push(...this.splitLines(element));
9191
const earlyReturn = this.checkBalance(element, i);
9292
if (!earlyReturn) return;
@@ -266,9 +266,12 @@ export default class SplitText {
266266
return found;
267267
}
268268

269-
replaceWords(element) {
269+
replaceWords(element, notByChars) {
270270
Array.from(element.getElementsByClassName('word')).forEach((el, i) => {
271271
el.replaceWith(this.words[i]);
272+
if (el.__isCJK && notByChars) {
273+
this.words[i].innerHTML = this.words[i].textContent;
274+
}
272275
});
273276
}
274277

@@ -325,6 +328,7 @@ export default class SplitText {
325328

326329
// If it's CJK, split into individual characters
327330
if (isCJKMode) {
331+
splitEl.__isCJK = true;
328332
this.chars.push(...this.splitElement(splitEl, 'char', '', false));
329333
}
330334
}

0 commit comments

Comments
 (0)