-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (41 loc) · 1.08 KB
/
index.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
var fs = require('fs');
var path = require('path');
var counter = 1;
function parseJS(filename){
var output = [];
var lines = fs.readFileSync(filename + ".md").toString().split("\n");
var inMd = true;
for (var i = 0; i < lines.length; i++){
var line = lines[i];
if (line.indexOf('```') >= 0){
inMd = !inMd;
output.push("");
} else {
if (!inMd){
output.push(line);
} else {
if (line.indexOf(' ') == 0){
output.push(line);
} else {
output.push("// " + line);
parseLine(line).forEach(function(sub){
output.push(sub);
});
}
}
}
}
output.push("// This javascript file was auto generated.");
output.push("var __markdown = require('fs').readFileSync('" + filename + ".md').toString();");
fs.writeFileSync(path.join(__dirname,"generated." + counter + ".js"), output.join("\n"));
return require(path.join(__dirname,"generated." + counter++ + ".js"));
}
function parseLine(line){
var parts = line.split('`');
var output = [];
for (i = 1; i < parts.length; i+=2){
output.push(parts[i]);
}
return output;
}
module.exports = parseJS;