Skip to content

Commit

Permalink
Fix handling of maxNesting errors in block parser
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Jan 13, 2015
1 parent ba460b1 commit 41e55b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions lib/parser_block.js
Expand Up @@ -59,23 +59,32 @@ ParserBlock.prototype.tokenize = function (state, startLine, endLine) {
// Nested calls currently used for blockquotes & lists
if (state.tShift[line] < state.blkIndent) { break; }

// 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.line = endLine;
break;
}

// Try all possible rules.
// On success, rule should:
//
// - update `state.line`
// - update `state.tokens`
// - return true

for (i = 0; i < len; i++) {
ok = rules[i](state, line, endLine, false);
if (ok) { break; }
if (state.level >= maxNesting) {
// In case maxNesting is reached, output the rest of the lines
// as plain inline tokens one by one.
state.tokens.push({
type: 'inline',
content: state.src.slice(
state.bMarks[state.line] + state.tShift[state.line],
state.eMarks[state.line]
).trim(),
level: state.level,
lines: [ state.line, state.line ],
children: []
});
state.line++;
} else {
for (i = 0; i < len; i++) {
ok = rules[i](state, line, endLine, false);
if (ok) { break; }
}
}

// set state.tight iff we had an empty line before current tag
Expand Down
2 changes: 1 addition & 1 deletion test/misc.js
Expand Up @@ -244,7 +244,7 @@ describe('maxNesting', function () {
var md = markdownit({ maxNesting: 2 });
assert.strictEqual(
md.render('>foo\n>>bar\n>>>baz'),
'<blockquote>\n<p>foo</p>\n<blockquote>\n</blockquote>\n</blockquote>\n'
'<blockquote>\n<p>foo</p>\n<blockquote>\nbar&gt;baz</blockquote>\n</blockquote>\n'
);
});

Expand Down

0 comments on commit 41e55b5

Please sign in to comment.