Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop creating paragraphs in tight lists #349

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 2 additions & 0 deletions packages/remark-parse/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function Parser(doc, file) {
this.setOptions({});

this.inList = false;
this.inTightList = false;
this.inBlock = false;
this.inLink = false;
this.atStart = true;
Expand All @@ -37,6 +38,7 @@ proto.options = require('./defaults');
/* Enter and exit helpers. */
proto.exitStart = toggle('atStart', true);
proto.enterList = toggle('inList', false);
proto.enterTightList = toggle('inTightList', false);
proto.enterLink = toggle('inLink', false);
proto.enterBlock = toggle('inBlock', false);

Expand Down
21 changes: 18 additions & 3 deletions packages/remark-parse/lib/tokenize/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ function listItem(ctx, value, position) {
var checked = null;
var task;
var indent;
var loose;
var children;
var exit;

value = fn.apply(null, arguments);

Expand All @@ -382,12 +385,24 @@ function listItem(ctx, value, position) {
}
}

loose = EXPRESSION_LOOSE_LIST_ITEM.test(value) ||
value.charAt(value.length - 1) === C_NEWLINE;

if (!loose) {
exit = ctx.enterTightList();
}

children = ctx.tokenizeBlock(value, position);

if (!loose) {
exit();
}

return {
type: 'listItem',
loose: EXPRESSION_LOOSE_LIST_ITEM.test(value) ||
value.charAt(value.length - 1) === C_NEWLINE,
loose: loose,
checked: checked,
children: ctx.tokenizeBlock(value, position)
children: children
};
}

Expand Down
17 changes: 15 additions & 2 deletions packages/remark-parse/lib/tokenize/paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function paragraph(eat, value, silent) {
var character;
var size;
var now;
var children;
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn’t this make more sense in list-items?

var add;

while (index < length) {
/* Eat everything if there’s no following newline. */
Expand Down Expand Up @@ -115,8 +117,19 @@ function paragraph(eat, value, silent) {
now = eat.now();
subvalue = trimTrailingLines(subvalue);

return eat(subvalue)({
children = self.tokenizeInline(subvalue, now);
add = eat(subvalue);

/* Paragraphs in a loose list are wrapped in <p> tags, while paragraphs in a
* tight list are not */
if (self.inTightList) {
return children.map(function (child) {
return add(child);
});
}

return add({
type: 'paragraph',
children: self.tokenizeInline(subvalue, now)
children: children
});
}