Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this if statement be removed in favor of listStart.loose = loose

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no because if loose is false and listStart.loose is true I don't want it to change listStart.loose to false.

listStart.loose is true if any of listStart items are loose

}

// 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 @@ -1217,28 +1238,20 @@ Parser.prototype.tok = function() {
}
case 'list_item_start': {
body = '';
var loose = this.token.loose;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you create a new var here instead of using this.token.loose below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because this.token is changed when this.next() is called in the while loop below.

body += !this.token.loose && this.token.type === 'text' would be checking if the text token is loose not the list start token


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