diff --git a/lib/parser_inline.js b/lib/parser_inline.js index 4878ba0..13935c0 100644 --- a/lib/parser_inline.js +++ b/lib/parser_inline.js @@ -96,14 +96,9 @@ ParserInline.prototype.skipToken = function (state) { return; } } - state.pos++; - - } else { - // If nesting level exceeded - skip tail to the end. That's not ordinary - // situation and we should not care about content. - state.pos = state.max; } + state.pos++; state.cacheSet(pos, state.pos); }; @@ -118,13 +113,6 @@ ParserInline.prototype.tokenize = function (state) { maxNesting = state.md.options.maxNesting; while (state.pos < end) { - - // If nesting level exceeded - skip tail to the end. That's not ordinary - // situation and we should not care about content. - if (state.level >= maxNesting) { - state.pos = end; - break; - } // Try all possible rules. // On success, rule should: // @@ -132,9 +120,11 @@ ParserInline.prototype.tokenize = function (state) { // - update `state.tokens` // - return true - for (i = 0; i < len; i++) { - ok = rules[i](state, false); - if (ok) { break; } + if (state.level < maxNesting) { + for (i = 0; i < len; i++) { + ok = rules[i](state, false); + if (ok) { break; } + } } if (ok) { diff --git a/test/misc.js b/test/misc.js index f21f9af..d121a4d 100644 --- a/test/misc.js +++ b/test/misc.js @@ -222,3 +222,13 @@ describe('Links validation', function () { }); }); + + +describe('maxNesting', function () { + + it('Inline parser', function () { + var md = markdownit({ maxNesting: 2 }); + assert.strictEqual(md.render('*foo *bar *baz* bar* foo*'), '
foo bar *baz* bar foo
\n'); + }); + +});