Skip to content

Commit b58de92

Browse files
chitoku-kpurefun
authored andcommitted
fix: keep non-linebreak whitespaces
1 parent ee1f672 commit b58de92

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const range = str => str.split('-').map(c => `\\u${c}`).join('-');
2424

2525
const CJK = cjk_ranges.map(range).join('');
2626

27-
const regex = new RegExp(`([${CJK}])([\\s\\n]+)([${CJK}])`, 'gm');
27+
const regex = new RegExp(`([${CJK}])(\\s*\\n+\\s*)([${CJK}])`, 'gm');
2828

2929
function joinCKJLines(tree) {
3030
visit(tree, 'text', node => {

test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ describe('remark-join-cjk-lines', () => {
3030
expect(output).toBe('汉字换,行');
3131
});
3232

33-
it('should keep the space between non-cjk charactors', () => {
33+
it('should keep non-linebreak space between cjk characters', () => {
34+
const input = ['汉字 换', ' 行'].join('\n');
35+
const output = process(input);
36+
expect(output).toBe('汉字 换行');
37+
});
38+
39+
it('should keep the space between non-cjk characters', () => {
3440
const input = ['non-cjk', '行'].join('\n');
3541
const output = process(input);
3642
expect(output).toBe('non-cjk\n行');

0 commit comments

Comments
 (0)