feat: 自动在中英文之间添加空格,以改善排版

This commit is contained in:
Zhicheng Wang 2018-03-20 17:09:18 +08:00
parent df15324377
commit 545d4b6c69
63 changed files with 3761 additions and 3742 deletions

View File

@ -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);