Skip to content

Commit ca5129b

Browse files
committed
fix: use emoji regex to correctly mask pair emojis
1 parent 15c77de commit ca5129b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

package-lock.json

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"commonmark": "0.31.2",
6161
"cross-env": "^10.1.0",
6262
"dts-bundle-generator": "^9.5.1",
63+
"emoji-regex": "^10.6.0",
6364
"esbuild": "^0.27.0",
6465
"esbuild-plugin-umd-wrapper": "^3.0.0",
6566
"eslint": "^9.39.1",

src/Lexer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import emojiRegex from 'emoji-regex';
12
import { _Tokenizer } from './Tokenizer.ts';
23
import { _defaults } from './defaults.ts';
34
import { other, block, inline } from './rules.ts';
@@ -330,6 +331,9 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
330331
// Mask out blocks from extensions
331332
maskedSrc = this.options.hooks?.emStrongMask?.call({ lexer: this }, maskedSrc) ?? maskedSrc;
332333

334+
const emojiMatcher = emojiRegex();
335+
maskedSrc = maskedSrc.replace(emojiMatcher, (m) => 'a'.repeat(m.length));
336+
333337
let keepPrevChar = false;
334338
let prevChar = '';
335339
while (src) {

0 commit comments

Comments
 (0)