Skip to content

Commit

Permalink
Merge pull request #1464 from UziTech/nested-blockquotes
Browse files Browse the repository at this point in the history
Nested blockquotes
  • Loading branch information
joshbruce authored May 3, 2019
2 parents 5d727cb + 0620845 commit 67b91cf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
40 changes: 33 additions & 7 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ Lexer.prototype.token = function(src, top) {
l,
isordered,
istask,
ischecked;
ischecked,
blockquote,
count;

while (src) {
// newline
Expand Down Expand Up @@ -306,16 +308,26 @@ Lexer.prototype.token = function(src, top) {
type: 'blockquote_start'
});

cap = cap[0].replace(/^ *> ?/gm, '');
blockquote = cap[0].replace(/^ *> ?/gm, '');
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 @@ -1240,13 +1252,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
4 changes: 4 additions & 0 deletions test/redos/nested_blockquote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
markdown: '>'.repeat(5000),
html: '<blockquote>'.repeat(5000) + '</blockquote>'.repeat(5000)
};
4 changes: 2 additions & 2 deletions test/specs/redos-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('ReDOS tests', () => {
return;
}

it(file, () => {
const spec = require(path.resolve(redosDir, file));
const spec = require(path.resolve(redosDir, file));
(spec.only ? fit : it)(file, () => {
const before = process.hrtime();
expect(spec).toRender(spec.html);
const elapsed = process.hrtime(before);
Expand Down

0 comments on commit 67b91cf

Please sign in to comment.