From a22ef0f4a4d5ec2596556fa7bb382d30cfe71e9b Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 3 Jul 2018 08:23:03 -0500 Subject: [PATCH 1/3] loose lists --- lib/marked.js | 32 ++++++++++++++++++++---- test/specs/commonmark/commonmark-spec.js | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 81c482d41c..42a9b80884 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,16 @@ Lexer.prototype.token = function(src, top) { item = item.replace(/^\[[ xX]\] +/, ''); } - this.tokens.push({ + t = { type: loose ? 'loose_item_start' : 'list_item_start', task: istask, checked: ischecked - }); + }; + + listItems.push(t); + this.tokens.push(t); // Recurse. this.token(item, false); @@ -389,6 +403,14 @@ Lexer.prototype.token = function(src, top) { }); } + if (listStart.loose) { + l = listItems.length; + i = 0; + for (; i < l; i++) { + listItems[i].type = 'loose_item_start'; + } + } + this.tokens.push({ type: 'list_end' }); diff --git a/test/specs/commonmark/commonmark-spec.js b/test/specs/commonmark/commonmark-spec.js index 4205044586..72b21f41bb 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 = []; From b167cd410c327800782f1e077cbd58750f0bfdc6 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 3 Jul 2018 08:33:51 -0500 Subject: [PATCH 2/3] remove loose_item_start token fixes #469 --- lib/marked.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 42a9b80884..79fe1191f5 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -385,11 +385,10 @@ Lexer.prototype.token = function(src, top) { } t = { - type: loose - ? 'loose_item_start' - : 'list_item_start', + type: 'list_item_start', task: istask, - checked: ischecked + checked: ischecked, + loose: loose }; listItems.push(t); @@ -407,7 +406,7 @@ Lexer.prototype.token = function(src, top) { l = listItems.length; i = 0; for (; i < l; i++) { - listItems[i].type = 'loose_item_start'; + listItems[i].loose = true; } } @@ -1239,28 +1238,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); From ddd31aa94db68fc25931f8e3c641c573e13c37f0 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 9 Jul 2018 13:44:33 -0500 Subject: [PATCH 3/3] remove non-spec failing tests --- test/new/loose_lists.html | 62 --------------------------------------- test/new/loose_lists.md | 59 ------------------------------------- 2 files changed, 121 deletions(-) delete mode 100644 test/new/loose_lists.html delete mode 100644 test/new/loose_lists.md 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 @@ -
    -
  • 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/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