Skip to content

Commit

Permalink
no recursion for nested blockquotes
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Apr 9, 2019
1 parent 69c9e63 commit 8da970c
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,26 @@ Lexer.prototype.token = function(src, top) {
type: 'blockquote_start'
});

cap = cap[0].replace(/^ *> ?/gm, '');
var blockquote = cap[0].replace(/^ *> ?/gm, '');
var count = 1;
while (blockquote.match(/^ {0,3}>/)) {
count++;
this.tokens.push({
type: 'blockquote_start'
});
blockquote = blockquote.replace(/^ *> ?/gm, '');
}

// Pass `top` to keep the current
// "toplevel" state. This is exactly
// how markdown.pl works.
this.token(cap, top);
this.token(blockquote, top);

this.tokens.push({
type: 'blockquote_end'
});
for (i = 0; i < count; i++) {
this.tokens.push({
type: 'blockquote_end'
});
}

continue;
}
Expand Down Expand Up @@ -1233,13 +1243,27 @@ Parser.prototype.tok = function() {
return this.renderer.table(header, body);
}
case 'blockquote_start': {
var count = 1;
while (this.peek() && this.peek().type === 'blockquote_start') {
this.next();
count++;
}

body = '';

while (this.next().type !== 'blockquote_end') {
body += this.tok();
}

return this.renderer.blockquote(body);
while (this.peek() && this.peek().type === 'blockquote_end') {
this.next();
}

for (i = 0; i < count; i++) {
body = this.renderer.blockquote(body);
}

return body;
}
case 'list_start': {
body = '';
Expand Down

0 comments on commit 8da970c

Please sign in to comment.