From c30054fc3afa1378bf961572f5941009b94b89c1 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Sun, 4 Jan 2015 16:02:39 +0300 Subject: [PATCH] Improved preset name error reporting --- lib/index.js | 12 +++++++++--- support/api_header.md | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index 712b07d..5fdd237 100644 --- a/lib/index.js +++ b/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); } diff --git a/support/api_header.md b/support/api_header.md index 62893fa..d813761 100644 --- a/support/api_header.md +++ b/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