forked from JohnMcLear/ep_markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (39 loc) · 1.54 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
45
46
47
48
49
50
51
var path = require('path');
var eejs = require("ep_etherpad-lite/node/eejs");
var settings = require('ep_etherpad-lite/node/utils/Settings');
var fs = require("fs");
exports.eejsBlock_exportColumn = function(hook_name, args, cb) {
args.content = args.content + eejs.require("ep_markdown/templates/exportcolumn.html", {}, module);
return cb();
};
exports.eejsBlock_scripts = function (hook_name, args, cb) {
args.content = args.content + eejs.require("ep_markdown/templates/scripts.html", {}, module);
return cb();
};
exports.eejsBlock_styles = function (hook_name, args, cb) {
args.content = args.content + eejs.require("ep_markdown/templates/styles.html", {}, module);
return cb();
};
exports.eejsBlock_mySettings = function (hook_name, args, cb) {
if (!settings.ep_markdown_default){
checked_state = 'unchecked';
}else{
if(settings.ep_markdown_default == true){
checked_state = 'checked';
}
}
args.content = args.content + eejs.require('ep_markdown/templates/markdown_entry.ejs', {checked : checked_state});
return cb();
}
exports.import = function (hook_name, args ,callback){
if(args.fileEnding.indexOf(".md") === -1) return callback();
// It is Markdown file, let's go!
var markdown = fs.readFileSync(args.srcFile, 'utf-8');
var showdown = require('showdown');
var converter = new showdown.Converter({completeHTMLDocument: true});
var html = converter.makeHtml(markdown);
fs.writeFile(args.destFile, html, 'utf8', function(err){
if(err) callback(err, null);
callback(args.destFile);
});
}