forked from pegaltier/awesome-utils-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remark.js
72 lines (56 loc) · 1.43 KB
/
remark.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var unified = require('unified')
var stream = require('unified-stream')
var vfile = require('to-vfile')
// remark features
var remark = require('remark')
var markdown = require('remark-parse')
var remark2rehype = require('remark-rehype')
var html = require('rehype-stringify')
var breaks = require('remark-breaks')
var toc = require('remark-toc')
var fs = require('fs');
// Process file and create correct markdown
var input = 'utils-management.md';
var newContent1 = "";
var newContent2 = "";
// break https://github.com/remarkjs/remark-breaks
unified()
.use(markdown)
.use(breaks)
.use(remark2rehype)
.use(html)
.use(toc)
.process(vfile.readSync(input), function(err, file) {
if (err) throw err
newContent1 = String(file);
console.log('process1 ok')
})
// console.log('step ok', newContent1)
//process.stdin.pipe(stream(processor)).pipe(process.stdout)
// Write the new file
fs.writeFile(input, newContent1, function (err) {
if (err) {
return console.log(err);
}
console.log('write1 ok');
});
// Generate TOC
// https://github.com/remarkjs/remark-toc
/*
remark()
.use(toc)
.process(vfile.readSync(file), function(err, file) {
if (err) throw err
// newContent2 = file
console.log('toc ok', String(file))
})
*/
/*
// Write the new file
fs.writeFile(file, newContent2, function(err) {
if(err) {
return console.log(err);
}
console.log('write2 ok');
}); */
//process.exit(0);