forked from KrauseFx/markdown-to-html-github-style
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.js
51 lines (43 loc) · 1.23 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
var showdown = require('showdown');
var fs = require('fs');
let filename = "README.md"
let pageTitle = process.argv[2] || ""
fs.readFile(__dirname + '/style.css', function (err, styleData) {
fs.readFile(process.cwd() + '/' + filename, function (err, data) {
if (err) {
throw err;
}
let text = data.toString();
converter = new showdown.Converter({
ghCompatibleHeaderId: true,
simpleLineBreaks: true,
ghMentions: true,
tables: true
});
let preContent = `
<html>
<head>
<title>` + pageTitle + `</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id='content'>
`
let postContent = `
</div>
<style type='text/css'>` + styleData + `</style>
</body>
</html>`;
html = preContent + converter.makeHtml(text) + postContent
converter.setFlavor('github');
console.log(html);
let filePath = process.cwd() + "/README.html";
fs.writeFile(filePath, html, { flag: "wx" }, function(err) {
if (err) {
console.log("File '" + filePath + "' already exists. Aborted!");
} else {
console.log("Done, saved to " + filePath);
}
});
});
});