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,}/,
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 '<li>'
+ body.join(' ')
+ '</li>';
case 'loose_item_start':
var body = [];
while (next().type !== 'list_item_end') {
body.push(tok());
}
return '<li>'
+ body.join(' ')
+ '</li>';
case 'html':
return inline.lexer(token.text);
case 'text':

View File

@ -22,7 +22,12 @@ markdown.js doesnt acknowledge arbitrary html blocks =/</aside>
* 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

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
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>