Browse Source

Better error message for bad input type, close #324

pull/343/head
Vitaly Puzrin 8 years ago
parent
commit
c9199b582d
  1. 4
      lib/index.js
  2. 9
      test/misc.js

4
lib/index.js

@ -514,6 +514,10 @@ MarkdownIt.prototype.use = function (plugin /*, params, ... */) {
* and then pass updated object to renderer. * and then pass updated object to renderer.
**/ **/
MarkdownIt.prototype.parse = function (src, env) { MarkdownIt.prototype.parse = function (src, env) {
if (typeof src !== 'string') {
throw new Error('Input data should be a String');
}
var state = new this.core.State(src, this, env); var state = new this.core.State(src, this, env);
this.core.process(state); this.core.process(state);

9
test/misc.js

@ -145,6 +145,15 @@ describe('API', function () {
assert(md.renderInline('_foo_'), '<em>foo</em>'); assert(md.renderInline('_foo_'), '<em>foo</em>');
}); });
it('input type check', function () {
var md = markdownit();
assert.throws(
function () { md.render(null); },
/Input data should be a String/
);
});
}); });

Loading…
Cancel
Save