Skip to content

Commit

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

* Update utils.test.ts
  • Loading branch information
sxjeru authored Oct 14, 2024
1 parent 1d4872c commit 53e8aac
Show file tree
Hide file tree
Showing 2 changed files with 9 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

0 comments on commit 53e8aac

Please sign in to comment.