Skip to content

Preserve whitespace inside nodes if necessary #676

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

Merged
merged 5 commits into from
Jun 26, 2017
Merged

Preserve whitespace inside nodes if necessary #676

merged 5 commits into from
Jun 26, 2017

Conversation

Rich-Harris
Copy link
Member

Fixes #608. Whitespace handling is moved out of the parser and into the compiler, where we can be a bit smarter.

Essentially, Svelte keeps track of what the next sibling is while 'preprocessing' nodes, and uses that knowledge to determine whether whitespace should be removed from the end of a fragment:

<h1>Hello <strong>{{name}}! </strong><span>How are you?</span></h1>

The ! text node is aware that its parent element's next sibling is a <span> element rather than a text node with leading whitespace, so it knows to preserve the space after the exclamation mark. This would also be true if the <strong> element was wrapped in one or more elements.

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.

1 participant