Browse Source

Improved preset name error reporting

pull/30/head
Vitaly Puzrin 10 years ago
parent
commit
c30054fc3a
  1. 12
      lib/index.js
  2. 4
      support/api_header.md

12
lib/index.js

@ -212,7 +212,7 @@ function MarkdownIt(presetName, options) {
this.options = {};
this.configure(config[presetName]);
this.configure(presetName);
if (options) { this.set(options); }
}
@ -254,9 +254,15 @@ MarkdownIt.prototype.set = function (options) {
* will give better compatibility with next versions.
**/
MarkdownIt.prototype.configure = function (presets) {
var self = this;
var self = this, presetName;
if (!presets) { throw new Error('Wrong `markdown-it` preset, check name/content'); }
if (utils.isString(presets)) {
presetName = presets;
presets = config[presetName];
if (!presets) { throw new Error('Wrong `markdown-it` preset "' + presetName + '", check name'); }
}
if (!presets) { throw new Error('Wrong `markdown-it` preset, can\'t be empty'); }
if (presets.options) { self.set(presets.options); }

4
support/api_header.md

@ -12,10 +12,10 @@ In most cases you will use `markdown-it` in very simple way:
```javascript
var md = require('markdown-it')();
var result = md.render(your_markdown_string);
var result = md.render('your_markdown_string');
// Or for inline (without paragraths & blocks)
var resultInline = md.renderInline(your_markdown_inline_string);
var resultInline = md.renderInline('your_markdown_inline_string');
```
### Advanced use

Loading…
Cancel
Save