-
Notifications
You must be signed in to change notification settings - Fork 0
/
html2md.js
47 lines (25 loc) · 951 Bytes
/
html2md.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
var fs=require('fs')
var toMd = require('to-markdown')
var upndown = require('upndown');
var und = new upndown()
// CB helper
function cbDone (...args) { cbDone.next(args) }
cbDone.then = resolve=>cbDone.next=resolve
var files = fs.readdirSync("private/gdocs")
async function markdownize(files) {
var fileBody, fileContent
for (let f=0; f<files.length; f++) {
fileContent = fs.readFileSync('private/gdocs/' + files[f], 'utf8')
fileBody = /<body.*?>([\s\S]*)<\/body>/.exec(fileContent)[1];
und.convert(fileBody, cbDone)
var [err,markdown] = await cbDone
if (err) { console.err('---', files[f], err) }
else {
var mdFileName = 'private/md/' + files[f].replace('.html','.md')
fs.writeFileSync(mdFileName, markdown, 'utf8')
console.log('Done:', mdFileName)
} // Outputs: # Hello, World !
//if (f==1) break;
}
}
markdownize(files)