|
|
@ -17,32 +17,14 @@ var config = { |
|
|
|
commonmark: require('./configs/commonmark') |
|
|
|
}; |
|
|
|
|
|
|
|
function configure(self, setupName) { |
|
|
|
var cfg = config[setupName]; |
|
|
|
|
|
|
|
if (!cfg) { throw new Error('Wrong config name'); } |
|
|
|
|
|
|
|
if (cfg.options) { self.set(cfg.options); } |
|
|
|
|
|
|
|
if (cfg.components) { |
|
|
|
Object.keys(cfg.components).forEach(function (name) { |
|
|
|
if (cfg.components[name].rules) { |
|
|
|
self[name].ruler.enable(cfg.components[name].rules, true); |
|
|
|
} |
|
|
|
if (cfg.components[name].options) { |
|
|
|
self[name].set(cfg.components[name].options); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Main class
|
|
|
|
//
|
|
|
|
function Remarkable(setupName, options) { |
|
|
|
function Remarkable(presetName, options) { |
|
|
|
if (!options) { |
|
|
|
if (!isString(setupName)) { |
|
|
|
options = setupName || {}; |
|
|
|
setupName = 'default'; |
|
|
|
if (!isString(presetName)) { |
|
|
|
options = presetName || {}; |
|
|
|
presetName = 'default'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -60,7 +42,7 @@ function Remarkable(setupName, options) { |
|
|
|
this.inline.typographer = this.typographer; |
|
|
|
this.inline.linkifier = this.linkifier; |
|
|
|
|
|
|
|
configure(this, setupName.toLowerCase()); |
|
|
|
this.configure(config[presetName]); |
|
|
|
|
|
|
|
if (options) { this.set(options); } |
|
|
|
} |
|
|
@ -73,6 +55,28 @@ Remarkable.prototype.set = function (options) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Batch loader for components rules states & options
|
|
|
|
//
|
|
|
|
Remarkable.prototype.configure = function (presets) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
if (!presets) { throw new Error('Wrong config name'); } |
|
|
|
|
|
|
|
if (presets.options) { self.set(presets.options); } |
|
|
|
|
|
|
|
if (presets.components) { |
|
|
|
Object.keys(presets.components).forEach(function (name) { |
|
|
|
if (presets.components[name].rules) { |
|
|
|
self[name].ruler.enable(presets.components[name].rules, true); |
|
|
|
} |
|
|
|
if (presets.components[name].options) { |
|
|
|
self[name].set(presets.components[name].options); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Sugar for curried plugins init:
|
|
|
|
//
|
|
|
|
// var md = new Remarkable();
|
|
|
|