Browse Source

Exposed `configure()` method

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
a0691ac720
  1. 50
      lib/index.js

50
lib/index.js

@ -17,32 +17,14 @@ var config = {
commonmark: require('./configs/commonmark') 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 // Main class
// //
function Remarkable(setupName, options) { function Remarkable(presetName, options) {
if (!options) { if (!options) {
if (!isString(setupName)) { if (!isString(presetName)) {
options = setupName || {}; options = presetName || {};
setupName = 'default'; presetName = 'default';
} }
} }
@ -60,7 +42,7 @@ function Remarkable(setupName, options) {
this.inline.typographer = this.typographer; this.inline.typographer = this.typographer;
this.inline.linkifier = this.linkifier; this.inline.linkifier = this.linkifier;
configure(this, setupName.toLowerCase()); this.configure(config[presetName]);
if (options) { this.set(options); } 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: // Sugar for curried plugins init:
// //
// var md = new Remarkable(); // var md = new Remarkable();

Loading…
Cancel
Save