loose
This commit is contained in:
parent
324d526538
commit
3c0baff53a
@ -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':
|
||||||
|
@ -24,6 +24,11 @@ markdown.js doesnt acknowledge arbitrary html blocks =/</aside>
|
|||||||
* 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
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<h1>A heading</h1> <p>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 <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'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 <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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user