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

Fix: enhance collapse whitespace (#145) #160

Merged
merged 2 commits into from
Sep 15, 2021

Conversation

SukkaW
Copy link
Contributor

@SukkaW SukkaW commented Sep 14, 2021

TL; DR: This closes #145.

Long description:

The PR handles an edge case when a noTrimWhitespacesInsideElement is right next to a noTrimWhitespacesArroundElement, and both of them have the text content surrounded by whitespace. The previous implementation is simply keeping those whitespaces, result in redundant whitespaces.

cc @thewilkybarkid

@netlify
Copy link

netlify bot commented Sep 14, 2021

‼️ Deploy request for htmlnano rejected.

Name Link
🔨 Latest commit 8c83715

Comment on lines -46 to +47
(
collapseType === 'aggressive' &&
!noTrimWhitespacesInsideElements.has(tag)
)
collapseType === 'aggressive'
Copy link
Contributor Author

@SukkaW SukkaW Sep 14, 2021

Choose a reason for hiding this comment

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

Here I move noTrimWhitespacesInsideElements determination to the inside of collapseRedundantWhitespaces method, in order to handle the edge case mentioned in #145.

Comment on lines -57 to 60
node.content = collapseWhitespace(node.content, options, collapseType, node.tag);
node.content = collapseWhitespace(node.content, options, collapseType, {
node,
prevNode,
nextNode
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the collapseRedundantWhitespaces method can access more information about the parent node.

Copy link
Member

@maltsev maltsev left a comment

Choose a reason for hiding this comment

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

👍

@maltsev maltsev merged commit 8b48693 into posthtml:master Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redundant whitespace not removed
2 participants