feat: 自动在中英文之间添加空格,以改善排版
This commit is contained in:
parent
df15324377
commit
545d4b6c69
|
@ -0,0 +1,19 @@
|
|||
import * as fs from 'fs';
|
||||
import { dirs } from '../dirs';
|
||||
import { listMarkdownFiles } from '../extractor';
|
||||
|
||||
export function addSpaces(sourceDir: string): void {
|
||||
const files = listMarkdownFiles(sourceDir);
|
||||
files.forEach(fileName => {
|
||||
console.log('adding spaces ...', fileName);
|
||||
const content = fs.readFileSync(fileName, 'utf8');
|
||||
const result = content
|
||||
.replace(/([\u4e00-\u9fa5])([a-zA-Z0-9`])/g, '$1 $2')
|
||||
.replace(/([a-zA-Z0-9`])([\u4e00-\u9fa5])/g, '$1 $2')
|
||||
;
|
||||
fs.writeFileSync(fileName, result, 'utf8');
|
||||
console.log('added spaces ', fileName);
|
||||
});
|
||||
}
|
||||
|
||||
addSpaces(dirs.content);
|
Loading…
Reference in New Issue