diff --git a/lib/marked.js b/lib/marked.js index 796419b712..caa54243f9 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -191,6 +191,9 @@ Lexer.prototype.token = function(src, top) { bull, b, item, + listStart, + listItems, + t, space, i, tag, @@ -316,15 +319,19 @@ Lexer.prototype.token = function(src, top) { bull = cap[2]; isordered = bull.length > 1; - this.tokens.push({ + listStart = { type: 'list_start', ordered: isordered, - start: isordered ? +bull : '' - }); + start: isordered ? +bull : '', + loose: false + }; + + this.tokens.push(listStart); // Get each top-level item. cap = cap[0].match(this.rules.item); + listItems = []; next = false; l = cap.length; i = 0; @@ -365,6 +372,10 @@ Lexer.prototype.token = function(src, top) { if (!loose) loose = next; } + if (loose) { + listStart.loose = true; + } + // Check for task list items istask = /^\[[ xX]\] /.test(item); ischecked = undefined; @@ -373,13 +384,15 @@ Lexer.prototype.token = function(src, top) { item = item.replace(/^\[[ xX]\] +/, ''); } - this.tokens.push({ - type: loose - ? 'loose_item_start' - : 'list_item_start', + t = { + type: 'list_item_start', task: istask, - checked: ischecked - }); + checked: ischecked, + loose: loose + }; + + listItems.push(t); + this.tokens.push(t); // Recurse. this.token(item, false); @@ -389,6 +402,14 @@ Lexer.prototype.token = function(src, top) { }); } + if (listStart.loose) { + l = listItems.length; + i = 0; + for (; i < l; i++) { + listItems[i].loose = true; + } + } + this.tokens.push({ type: 'list_end' }); @@ -1221,28 +1242,20 @@ Parser.prototype.tok = function() { } case 'list_item_start': { body = ''; + var loose = this.token.loose; if (this.token.task) { body += this.renderer.checkbox(this.token.checked); } while (this.next().type !== 'list_item_end') { - body += this.token.type === 'text' + body += !loose && this.token.type === 'text' ? this.parseText() : this.tok(); } return this.renderer.listitem(body); } - case 'loose_item_start': { - body = ''; - - while (this.next().type !== 'list_item_end') { - body += this.tok(); - } - - return this.renderer.listitem(body); - } case 'html': { // TODO parse inline content if parameter markdown=1 return this.renderer.html(this.token.text); diff --git a/test/new/loose_lists.html b/test/new/loose_lists.html deleted file mode 100644 index c1bd82a26a..0000000000 --- a/test/new/loose_lists.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - -

better behavior:

- - - - - - - - - - - - - - - - - - - - - - diff --git a/test/new/loose_lists.md b/test/new/loose_lists.md deleted file mode 100644 index cb360a15d7..0000000000 --- a/test/new/loose_lists.md +++ /dev/null @@ -1,59 +0,0 @@ -* hello - world - - how - are -* you - - - -better behavior: - -* hello - * world - how - - are - you - - * today -* hi - - - -* hello - -* world -* hi - - - -* hello -* world - -* hi - - - -* hello -* world - - how -* hi - - - -* hello -* world -* how - - are - - - -* hello -* world - -* how - - are diff --git a/test/specs/commonmark/commonmark-spec.js b/test/specs/commonmark/commonmark-spec.js index ef6ba20108..3bc003fbb7 100644 --- a/test/specs/commonmark/commonmark-spec.js +++ b/test/specs/commonmark/commonmark-spec.js @@ -259,7 +259,7 @@ describe('CommonMark 0.28 Lists', function() { var section = 'Lists'; // var shouldPassButFails = []; - var shouldPassButFails = [282, 270, 280, 278, 273, 275, 274, 264, 277, 265, 276, 279, 267, 269]; + var shouldPassButFails = [282, 270, 280, 278, 273, 274, 264, 265, 276, 279, 267, 269]; var willNotBeAttemptedByCoreTeam = [];