diff --git a/src/Markdown/utils.test.ts b/src/Markdown/utils.test.ts index 786b2285..88eeec0d 100644 --- a/src/Markdown/utils.test.ts +++ b/src/Markdown/utils.test.ts @@ -62,4 +62,11 @@ describe('fixMarkdownBold', () => { `; expect(fixMarkdownBold(text)).toBe(expected); }); + + it('should not have a space after a bold character other than symbols', () => { + expect(fixMarkdownBold('你**我**他')).toBe('你**我**他'); + expect(fixMarkdownBold('你**我:**他')).toBe('你**我:** 他'); + expect(fixMarkdownBold('你**我:**他')).toBe('你**我:** 他'); + // expect(fixMarkdownBold('你**我: **他')).toBe('你**我:** 他'); // TODO: 先去掉加粗部分末尾空格,再在**后添加空格 + }); }); diff --git a/src/Markdown/utils.ts b/src/Markdown/utils.ts index efa64fba..8ab862fa 100644 --- a/src/Markdown/utils.ts +++ b/src/Markdown/utils.ts @@ -49,9 +49,9 @@ export function fixMarkdownBold(text: string): string { } if (count === 2 && count2 % 2 === 0) { const prevChar = i > 0 ? text[i - 2] : ''; - const isPrevCharAlphanumeric = /[a-zA-Z0-9]/.test(prevChar); + const isPrevCharSymbol = /[\p{P}\p{S}]/u.test(prevChar); - if (i + 1 < text.length && text[i + 1] !== ' ' && !isPrevCharAlphanumeric) { + if (i + 1 < text.length && text[i + 1] !== ' ' && isPrevCharSymbol) { result += '* '; } else { result += '*'; diff --git a/tsconfig.json b/tsconfig.json index 4d734bf3..25fbee3c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,8 @@ "esModuleInterop": true, "jsx": "react-jsx", "lib": ["dom", "dom.iterable", "esnext"], + "module": "esnext", + "moduleResolution": "node", "paths": { "@@/*": [".dumi/tmp/*"], "@/*": ["src/*"], @@ -19,6 +21,7 @@ "resolveJsonModule": true, "skipLibCheck": true, "strict": true, + "target": "es6", "types": ["vitest/globals"] }, "exclude": ["mdx.d.ts", "brand.d.ts"],