Skip to content

Commit 8da970c

Browse files
committed
no recursion for nested blockquotes
1 parent 69c9e63 commit 8da970c

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

lib/marked.js

+30-6
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,26 @@ Lexer.prototype.token = function(src, top) {
299299
type: 'blockquote_start'
300300
});
301301

302-
cap = cap[0].replace(/^ *> ?/gm, '');
302+
var blockquote = cap[0].replace(/^ *> ?/gm, '');
303+
var count = 1;
304+
while (blockquote.match(/^ {0,3}>/)) {
305+
count++;
306+
this.tokens.push({
307+
type: 'blockquote_start'
308+
});
309+
blockquote = blockquote.replace(/^ *> ?/gm, '');
310+
}
303311

304312
// Pass `top` to keep the current
305313
// "toplevel" state. This is exactly
306314
// how markdown.pl works.
307-
this.token(cap, top);
315+
this.token(blockquote, top);
308316

309-
this.tokens.push({
310-
type: 'blockquote_end'
311-
});
317+
for (i = 0; i < count; i++) {
318+
this.tokens.push({
319+
type: 'blockquote_end'
320+
});
321+
}
312322

313323
continue;
314324
}
@@ -1233,13 +1243,27 @@ Parser.prototype.tok = function() {
12331243
return this.renderer.table(header, body);
12341244
}
12351245
case 'blockquote_start': {
1246+
var count = 1;
1247+
while (this.peek() && this.peek().type === 'blockquote_start') {
1248+
this.next();
1249+
count++;
1250+
}
1251+
12361252
body = '';
12371253

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

1242-
return this.renderer.blockquote(body);
1258+
while (this.peek() && this.peek().type === 'blockquote_end') {
1259+
this.next();
1260+
}
1261+
1262+
for (i = 0; i < count; i++) {
1263+
body = this.renderer.blockquote(body);
1264+
}
1265+
1266+
return body;
12431267
}
12441268
case 'list_start': {
12451269
body = '';

0 commit comments

Comments
 (0)