diff --git a/lib/marked.js b/lib/marked.js index 49b81ef0..2062d703 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -16,10 +16,7 @@ var block = { lheading: /^([^\n]+)\n *(=|-){3,}/, hr: /^( ?[\-*_]){3,}/, blockquote: /^ *>[^\n]*(?:\n *>[^\n]*)*/, - // list: /^(?:( *)(\*|\+|-|\d+\.)[^\n]+(?:\n(?:\1 )+[^\n]+)*(?:\n+|$)){2,}/g, - // this can be simplified because its the whole list - //list: /^(?:( *)(\*|\+|-|\d+\.)[^\n]+(?:\n\1+[^\n]+)*(?:\n{1,2}|$)){2,}/g, - list: /^(?: *(\*|\+|-|\d+\.)[^\n]+(?:\n[^\n]+)*(\n{1,2}|$)){2,}/g, + list: /^(?: *(\*|\+|-|\d+\.)[^\n]+(?:\n[^\n]+)*(?:\n{1,2}|$)){2,}/g, html: /^<([^\/\s>]+)[^\n>]*>[^\n]*(?:\n[^\n]+)*\n?<\/\1>/, text: /^[^\n]+/ }; @@ -123,7 +120,12 @@ block.token = function(str, tokens) { }); break; case 'list': - var loose = false; //cap[2].length === 2; + //var loose = false; //cap[2].length === 2; + var loose = new RegExp( + '\n *\n' + + cap[1] + + '(?:\\*|\\+|-|\\d+\\.)' + ).test(cap[0]); tokens.push({ type: 'list_start', ordered: isFinite(cap[1]) @@ -146,7 +148,7 @@ block.token = function(str, tokens) { } tokens.push({ type: loose - ? 'loose_list_item_start' + ? 'loose_item_start' : 'list_item_start' }); block.token(item, tokens); @@ -396,8 +398,6 @@ var tok = function() { case 'list_item_start': var body = []; while (next().type !== 'list_item_end') { - // TODO incorporate paragraph - // list items here body.push(token.type === 'text' ? inline.lexer(token.text) : tok()); @@ -405,6 +405,14 @@ var tok = function() { return '
  • ' + body.join(' ') + '
  • '; + case 'loose_item_start': + var body = []; + while (next().type !== 'list_item_end') { + body.push(tok()); + } + return '
  • ' + + body.join(' ') + + '
  • '; case 'html': return inline.lexer(token.text); case 'text': diff --git a/test/in.md b/test/in.md index bc47d2c5..99a8c272 100644 --- a/test/in.md +++ b/test/in.md @@ -22,13 +22,18 @@ markdown.js doesnt acknowledge arbitrary html blocks =/ * New List Item 3 The last item * List Item 3 - The final item. +The final item. + +* List Item 4 +The real final item. + +Paragraph. > * bq Item 1 > * bq Item 2 > * New bq Item 1 > * New bq Item 2 -> Text here +> Text here > Another blockquote! > I really need to get diff --git a/test/out.html b/test/out.html index 1f38a7c4..0841ee2e 100644 --- a/test/out.html +++ b/test/out.html @@ -1,4 +1,4 @@

    A heading

    Just a note, I've found that I can't test my markdown parser vs others. For example, both markdown.js and showdown code blocks in lists wrong. They're also completely inconsistent with regards to paragraphs in list items.

    A link. Not anymore.

    Another blockquote! I really need to get more creative with mockup text.. markdown.js breaks here again

    Another Heading

    Hello world. Here is a link. And an image alt.

    Code goes here.
    +Lots of it...
  • New List Item 3 The last item
  • List Item 3 The final item.
  • List Item 4 The real final item.
  • Paragraph.

    Another blockquote! I really need to get more creative with mockup text.. markdown.js breaks here again

    Another Heading

    Hello world. Here is a link. And an image alt.

    Code goes here.
     Lots of it...