Skip to content

Commit

Permalink
🐛fix: Remove excess space in bold Chinese (new) (#212)
Browse files Browse the repository at this point in the history
* Update utils.ts

* Update utils.test.ts

* Update tsconfig.json

* Update tsconfig.json

* Update tsconfig.json
  • Loading branch information
sxjeru authored Oct 15, 2024
1 parent 1d4872c commit 7a60da3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Markdown/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: 先去掉加粗部分末尾空格,再在**后添加空格
});
});
4 changes: 2 additions & 2 deletions src/Markdown/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 += '*';
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"esModuleInterop": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"paths": {
"@@/*": [".dumi/tmp/*"],
"@/*": ["src/*"],
Expand All @@ -19,6 +21,7 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "es6",
"types": ["vitest/globals"]
},
"exclude": ["mdx.d.ts", "brand.d.ts"],
Expand Down

0 comments on commit 7a60da3

Please sign in to comment.