Skip to content

Commit

Permalink
Merge pull request markedjs#1304 from UziTech/loose-lists
Browse files Browse the repository at this point in the history
loose lists
  • Loading branch information
joshbruce authored Jul 14, 2018
2 parents aa420da + 027f954 commit 0694c79
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 141 deletions.
51 changes: 32 additions & 19 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ Lexer.prototype.token = function(src, top) {
bull,
b,
item,
listStart,
listItems,
t,
space,
i,
tag,
Expand Down Expand Up @@ -316,15 +319,19 @@ Lexer.prototype.token = function(src, top) {
bull = cap[2];
isordered = bull.length > 1;

this.tokens.push({
listStart = {
type: 'list_start',
ordered: isordered,
start: isordered ? +bull : ''
});
start: isordered ? +bull : '',
loose: false
};

this.tokens.push(listStart);

// Get each top-level item.
cap = cap[0].match(this.rules.item);

listItems = [];
next = false;
l = cap.length;
i = 0;
Expand Down Expand Up @@ -365,6 +372,10 @@ Lexer.prototype.token = function(src, top) {
if (!loose) loose = next;
}

if (loose) {
listStart.loose = true;
}

// Check for task list items
istask = /^\[[ xX]\] /.test(item);
ischecked = undefined;
Expand All @@ -373,13 +384,15 @@ Lexer.prototype.token = function(src, top) {
item = item.replace(/^\[[ xX]\] +/, '');
}

this.tokens.push({
type: loose
? 'loose_item_start'
: 'list_item_start',
t = {
type: 'list_item_start',
task: istask,
checked: ischecked
});
checked: ischecked,
loose: loose
};

listItems.push(t);
this.tokens.push(t);

// Recurse.
this.token(item, false);
Expand All @@ -389,6 +402,14 @@ Lexer.prototype.token = function(src, top) {
});
}

if (listStart.loose) {
l = listItems.length;
i = 0;
for (; i < l; i++) {
listItems[i].loose = true;
}
}

this.tokens.push({
type: 'list_end'
});
Expand Down Expand Up @@ -1221,28 +1242,20 @@ Parser.prototype.tok = function() {
}
case 'list_item_start': {
body = '';
var loose = this.token.loose;

if (this.token.task) {
body += this.renderer.checkbox(this.token.checked);
}

while (this.next().type !== 'list_item_end') {
body += this.token.type === 'text'
body += !loose && this.token.type === 'text'
? this.parseText()
: this.tok();
}

return this.renderer.listitem(body);
}
case 'loose_item_start': {
body = '';

while (this.next().type !== 'list_item_end') {
body += this.tok();
}

return this.renderer.listitem(body);
}
case 'html': {
// TODO parse inline content if parameter markdown=1
return this.renderer.html(this.token.text);
Expand Down
62 changes: 0 additions & 62 deletions test/new/loose_lists.html

This file was deleted.

59 changes: 0 additions & 59 deletions test/new/loose_lists.md

This file was deleted.

2 changes: 1 addition & 1 deletion test/specs/commonmark/commonmark-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ describe('CommonMark 0.28 Lists', function() {
var section = 'Lists';

// var shouldPassButFails = [];
var shouldPassButFails = [282, 270, 280, 278, 273, 275, 274, 264, 277, 265, 276, 279, 267, 269];
var shouldPassButFails = [282, 270, 280, 278, 273, 274, 264, 265, 276, 279, 267, 269];

var willNotBeAttemptedByCoreTeam = [];

Expand Down

0 comments on commit 0694c79

Please sign in to comment.