This commit is contained in:
Christopher Jeffrey 2011-08-20 08:59:47 -05:00
parent 324d526538
commit 3c0baff53a
3 changed files with 24 additions and 11 deletions

View File

@ -16,10 +16,7 @@ var block = {
lheading: /^([^\n]+)\n *(=|-){3,}/, lheading: /^([^\n]+)\n *(=|-){3,}/,
hr: /^( ?[\-*_]){3,}/, hr: /^( ?[\-*_]){3,}/,
blockquote: /^ *>[^\n]*(?:\n *>[^\n]*)*/, blockquote: /^ *>[^\n]*(?:\n *>[^\n]*)*/,
// list: /^(?:( *)(\*|\+|-|\d+\.)[^\n]+(?:\n(?:\1 )+[^\n]+)*(?:\n+|$)){2,}/g, list: /^(?: *(\*|\+|-|\d+\.)[^\n]+(?:\n[^\n]+)*(?:\n{1,2}|$)){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,
html: /^<([^\/\s>]+)[^\n>]*>[^\n]*(?:\n[^\n]+)*\n?<\/\1>/, html: /^<([^\/\s>]+)[^\n>]*>[^\n]*(?:\n[^\n]+)*\n?<\/\1>/,
text: /^[^\n]+/ text: /^[^\n]+/
}; };
@ -123,7 +120,12 @@ block.token = function(str, tokens) {
}); });
break; break;
case 'list': 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({ tokens.push({
type: 'list_start', type: 'list_start',
ordered: isFinite(cap[1]) ordered: isFinite(cap[1])
@ -146,7 +148,7 @@ block.token = function(str, tokens) {
} }
tokens.push({ tokens.push({
type: loose type: loose
? 'loose_list_item_start' ? 'loose_item_start'
: 'list_item_start' : 'list_item_start'
}); });
block.token(item, tokens); block.token(item, tokens);
@ -396,8 +398,6 @@ var tok = function() {
case 'list_item_start': case 'list_item_start':
var body = []; var body = [];
while (next().type !== 'list_item_end') { while (next().type !== 'list_item_end') {
// TODO incorporate paragraph
// list items here
body.push(token.type === 'text' body.push(token.type === 'text'
? inline.lexer(token.text) ? inline.lexer(token.text)
: tok()); : tok());
@ -405,6 +405,14 @@ var tok = function() {
return '<li>' return '<li>'
+ body.join(' ') + body.join(' ')
+ '</li>'; + '</li>';
case 'loose_item_start':
var body = [];
while (next().type !== 'list_item_end') {
body.push(tok());
}
return '<li>'
+ body.join(' ')
+ '</li>';
case 'html': case 'html':
return inline.lexer(token.text); return inline.lexer(token.text);
case 'text': case 'text':

View File

@ -22,13 +22,18 @@ markdown.js doesnt acknowledge arbitrary html blocks =/</aside>
* New List Item 3 * New List Item 3
The last item The last item
* List Item 3 * List Item 3
The final item. The final item.
* List Item 4
The real final item.
Paragraph.
> * bq Item 1 > * bq Item 1
> * bq Item 2 > * bq Item 2
> * New bq Item 1 > * New bq Item 1
> * New bq Item 2 > * New bq Item 2
> Text here > Text here
> Another blockquote! > Another blockquote!
> I really need to get > I really need to get

View File

@ -1,4 +1,4 @@
<h1>A heading</h1> <p>Just a note, I&apos;ve found that I can&apos;t test my markdown parser vs others. For example, both markdown.js and showdown code blocks in lists wrong. They&apos;re also completely <a href="http://google.com/" title="Google">inconsistent</a> with regards to paragraphs in list items.</p> <p>A link. Not anymore.</p> <aside>This will make me fail the test because <h1>A heading</h1> <p>Just a note, I&apos;ve found that I can&apos;t test my markdown parser vs others. For example, both markdown.js and showdown code blocks in lists wrong. They&apos;re also completely <a href="http://google.com/" title="Google">inconsistent</a> with regards to paragraphs in list items.</p> <p>A link. Not anymore.</p> <aside>This will make me fail the test because
markdown.js doesnt acknowledge arbitrary html blocks =/</aside> <ul><li>List Item 1</li><li>List Item 2 <ul><li>New List Item 1 Hi, this is a list item.</li><li>New List Item 2 Another item <pre><code>Code goes here. markdown.js doesnt acknowledge arbitrary html blocks =/</aside> <ul><li>List Item 1</li><li>List Item 2 <ul><li>New List Item 1 Hi, this is a list item.</li><li>New List Item 2 Another item <pre><code>Code goes here.
Lots of it...</code></pre></li><li>New List Item 3 The last item</li></ul></li><li>List Item 3 The final item.</li></ul> <blockquote><ul><li>bq Item 1</li><li>bq Item 2 <ul><li>New bq Item 1</li><li>New bq Item 2 Text here</li></ul></li></ul></blockquote> <blockquote><p> Another blockquote! I really need to get more creative with mockup text.. markdown.js breaks here again</p></blockquote> <h2>Another Heading</h2> <p>Hello <em>world</em>. Here is a <a href="//hello">link</a>. And an image <img src="src" alt="alt">.</p> <pre><code>Code goes here. Lots of it...</code></pre></li><li>New List Item 3 The last item</li></ul></li><li>List Item 3 The final item.</li><li>List Item 4 The real final item.</li></ul> <p>Paragraph.</p> <blockquote><ul><li>bq Item 1</li><li>bq Item 2 <ul><li>New bq Item 1</li><li>New bq Item 2 Text here</li></ul></li></ul></blockquote> <blockquote><p> Another blockquote! I really need to get more creative with mockup text.. markdown.js breaks here again</p></blockquote> <h2>Another Heading</h2> <p>Hello <em>world</em>. Here is a <a href="//hello">link</a>. And an image <img src="src" alt="alt">.</p> <pre><code>Code goes here.
Lots of it...</code></pre> Lots of it...</code></pre>