Browse Source

Fix maxNesting + tests

pull/41/head
Alex Kocharin 10 years ago
parent
commit
096f0fbb89
  1. 16
      lib/parser_inline.js
  2. 10
      test/misc.js

16
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,10 +120,12 @@ ParserInline.prototype.tokenize = function (state) {
// - update `state.tokens`
// - return true
if (state.level < maxNesting) {
for (i = 0; i < len; i++) {
ok = rules[i](state, false);
if (ok) { break; }
}
}
if (ok) {
if (state.pos >= end) { break; }

10
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*'), '<p><em>foo <em>bar *baz* bar</em> foo</em></p>\n');
});
});

Loading…
Cancel
Save