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

Whitespacer #81

Merged
merged 4 commits into from
Jun 26, 2017
Merged

Whitespacer #81

merged 4 commits into from
Jun 26, 2017

Conversation

yoshuawuyts
Copy link
Member

Fixes whitespace issues in text nodes, introduced in #74. Includes tests from #77.

Paves the way to fix shama/yo-yoify#48.

The algorithm is now aware of the sibling, and parent nodes of all text nodes and tries to collapse whitespace based on that. It respects <pre> and <code> blocks too, leaving whitespace as-is for those.

The code is rather complicated I feel, but this fixes the issue. If anyone wants to take a stab at a refactor / introduce more test cases that'd be grand. Thanks!

browser.js Outdated
if (i === 0) {
value = lastChild.nodeValue.replace(leadingNewlineRegex, '')
} else {
value = lastChild.nodeValue.replace(leadingNewlineRegex, ' ')
Copy link
Contributor

Choose a reason for hiding this comment

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

You could combine the above cases like this:

var leader = i === 0 ? '' : ' '
value = lastChild.nodeValue.replace(leadingNewlineRegex, leader)

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

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.

Incorrectly removed whitespaces
2 participants