smarter whitespace handling for list items

This commit is contained in:
Christopher Jeffrey 2012-01-28 07:32:05 -06:00
parent 9bbb0b71e1
commit 5809d6ad8d
5 changed files with 19 additions and 5 deletions

View File

@ -195,16 +195,18 @@ block.token = function(str, tokens, top) {
l = cap.length;
for (; i < l; i++) {
item = cap[i];
// Remove the list item's bullet
// so it is seen as the next token.
item = cap[i].replace(/^ *([*+-]|\d+\.) */, '');
space = item.length;
item = item.replace(/^ *([*+-]|\d+\.) */, '');
// Outdent whatever the
// list item contains. Hacky.
space = /\n( +)/.exec(item);
if (space) {
space = new RegExp('^' + space[1], 'gm');
item = item.replace(space, '');
if (~item.indexOf('\n ')) {
space -= item.length;
item = item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '');
}
tokens.push({

View File

@ -0,0 +1 @@
<ul><li><p>item1</p> <ul><li>item2 </li></ul> <p>text</p> </li></ul>

View File

@ -0,0 +1,5 @@
* item1
* item2
text

View File

@ -0,0 +1 @@
<ul><li><p>item1</p> <ul><li>item2 </li></ul> <p>text</p> </li></ul>

View File

@ -0,0 +1,5 @@
* item1
* item2
text