Skip to content

Commit

Permalink
Fix maxNesting + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Jan 12, 2015
1 parent e8994db commit 096f0fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
22 changes: 6 additions & 16 deletions lib/parser_inline.js
Expand Up @@ -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);
};

Expand All @@ -118,23 +113,18 @@ 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:
//
// - update `state.pos`
// - 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) {
Expand Down
10 changes: 10 additions & 0 deletions test/misc.js
Expand Up @@ -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*'), '<p><em>foo <em>bar *baz* bar</em> foo</em></p>\n');
});

});

0 comments on commit 096f0fb

Please sign in to comment.