Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛fix: Remove excess space in bold Chinese (new) #212

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading