-
Notifications
You must be signed in to change notification settings - Fork 3
/
node-editor.js
38 lines (32 loc) · 1.04 KB
/
node-editor.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
var pagedown = require("pagedown");
global.window.Markdown = pagedown;
global.window.Markdown.HookCollection = HookCollection;
var editor = require("./Markdown.Editor");
exports.getPagedownEditor = function() {
return new Markdown.Editor(pagedown.getSanitizingConverter());
}
function identity(x) { return x; }
function returnFalse(x) { return false; }
function HookCollection() { }
HookCollection.prototype = {
chain: function (hookname, func) {
var original = this[hookname];
if (!original)
throw new Error("unknown hook " + hookname);
if (original === identity)
this[hookname] = func;
else
this[hookname] = function (x) { return func(original(x)); }
},
set: function (hookname, func) {
if (!this[hookname])
throw new Error("unknown hook " + hookname);
this[hookname] = func;
},
addNoop: function (hookname) {
this[hookname] = identity;
},
addFalse: function (hookname) {
this[hookname] = returnFalse;
}
};