forked from fex-team/GMU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.js
39 lines (31 loc) · 944 Bytes
/
convert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @fileOverview 简单的markdown,代码格式转换工具
* 使用方法 `node convert.js ../_standard/README.md`
*
*/
(function() {
'use strict';
var files = [],
path = require('path'),
fs = require('fs'),
argv = process.argv,
len = argv.length,
i = 2;
for (; i < len; i++) {
files.push(argv[i]);
}
if (files.length) {
files.filter(function(file) {
return fs.existsSync(file);
}).forEach(function(file) {
var content = fs.readFileSync(file, 'utf-8'),
content = content.replace(/^```.*\n([\s\S]+?)^```/mg, function(m0, m1) {
return ('\n' + m1).replace(/^/mg, ' ');
});
file = file.replace(/\.([^\.]+)$/, '.convert.$1');
fs.writeFileSync(file, content, 'utf-8');
});
} else {
console.log('请指定文件');
}
})();