/
distillery.js
39 lines (30 loc) · 929 Bytes
/
distillery.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
/*
* Distillery
* Copyright (c) 2011 Kevin P. Albrecht
*/
var
fs = require('fs'),
Showdown = require('./lib/showdown').Showdown,
extract = require('./lib/extract').extract,
arguments = require('./lib/arguments');
var versionNumber = 'v0.3.0';
var argInfo = arguments.getArgumentInfo(versionNumber);
if (argInfo) {
var converter = new Showdown.converter();
var htmlContent;
if (argInfo.isRawMarkdown) {
htmlContent = converter.makeHtml(argInfo.input);
} else {
var blocks = extract(argInfo.input);
var convertedBlocks = blocks.map(function(block) {
return converter.makeHtml(block);
});
htmlContent = convertedBlocks.join(argInfo.middle);
}
var output = argInfo.start + htmlContent + argInfo.end;
if (argInfo.outputFile) {
fs.writeFileSync(argInfo.outputFile, output, 'utf8');
} else {
console.log(output);
}
}