diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 4f93a03..cc2f55c 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -725,7 +725,7 @@ export class Tokenizer { endReg.lastIndex = 0; // Clip maskedSrc to same section of string as src (move to lexer?) - maskedSrc = maskedSrc.slice(-1 * src.length + match[0].length - 1); + maskedSrc = maskedSrc.slice(-1 * src.length + lLength); while ((match = endReg.exec(maskedSrc)) != null) { // eslint-disable-next-line @@ -755,8 +755,9 @@ export class Tokenizer { // Remove extra characters. *a*** -> *a* rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal); - - const raw = [...src].slice(0, lLength + match.index + rLength + 1).join(""); + // char length can be >1 for unicode characters; + const lastCharLength = [...match[0]]![0]!.length; + const raw = src.slice(0, lLength + match.index + lastCharLength + rLength); // Create `em` if smallest delimiter has odd char count. *a*** if (Math.min(lLength, rLength) % 2) {