mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 23:16:20 +08:00
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
var Markdown;
|
|
|
|
if (typeof exports === "object" && typeof require === "function") // we're in a CommonJS (e.g. Node.js) module
|
|
Markdown = exports;
|
|
else
|
|
Markdown = {};
|
|
|
|
/**
|
|
This is only included so we have an interface that Pagedown can use.
|
|
**/
|
|
(function () {
|
|
|
|
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 (text) {
|
|
var args = Array.prototype.slice.call(arguments, 0);
|
|
args[0] = original.apply(null, args);
|
|
return func.apply(null, args);
|
|
};
|
|
},
|
|
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;
|
|
}
|
|
};
|
|
|
|
Markdown.HookCollection = HookCollection;
|
|
|
|
})();
|