From 7a60da3dcc1c0c61820cdd78ee96bf05d57704ee Mon Sep 17 00:00:00 2001 From: sxjeru Date: Tue, 15 Oct 2024 11:28:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9Bfix:=20Remove=20excess=20space=20in?= =?UTF-8?q?=20bold=20Chinese=20(new)=20(#212)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update utils.ts * Update utils.test.ts * Update tsconfig.json * Update tsconfig.json * Update tsconfig.json --- src/Markdown/utils.test.ts | 7 +++++++ src/Markdown/utils.ts | 4 ++-- tsconfig.json | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) 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"],