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