-
Notifications
You must be signed in to change notification settings - Fork 13
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
Should we trim whitespace #7
Comments
I agree. I don't think that anyone would intentionally want to create an empty text node before the element they are actually creating. |
Definitely, for example: function render() {
document.querySelector('main').diffElement(html`
<main>
<h1>${Date.now()}</h1>
</main>
`);
requestAnimationFrame(render);
}
render(); In order to make this example work as one would expect (diffing the same element structure), I'd need to manually trim the pre/post whitespace. |
I'm wary of this. I think this kind of magic is generally not something you want in a standards-based library. Every template string tag has this "problem" and the canonical solution is to just put your ```s snuggled up close to the content. It also seems counterintuitive that if I do something like @annevk, what do you think? |
I agree that would be bad. It should be as close as possible to the HTML parser, possibly the |
I guess I can get behind that because the intent is that this is adopted by the DOM API. I very rarely see users intentionally creating empty text nodes and So assuming that we don't |
I know Ember uses empty text nodes as "markers" for data-binding positions within the DOM. Not sure it's terribly relevant to this though :) |
I think we all agree that we shouldn't make any assumptions about what the user's intent was, so I'll close this issue with no action and default everything to the HTML parser. |
This has just bitten me when trying to use newlines. Without whitespace getting trimmed it's quite difficult to use this function without making a real mess of your code. Unless there's some trick I'm missing, this decision makes the library pretty much unusable for me. For reference, my code: this.html = html`<div>
<span>${pre}</span>
<img src=${favIconUrl}></img>
<span>${tab.index + 1}: ${tab.title}</span>
<a class="url" href=${tab.url}>${tab.url}</a>
</div>` I encourage you to revisit this decision - we all want our code to be easy to read, after all. |
Could you please describe what your expected output was? Running the provided code through |
Certainly :) I expected the input to be trimmed linewise. Concretely: html`<div>
<span></span>
<img src=foo></img>
<span>: </span>
<a class="url" href=foo></a>
</div>` gives a node with 9 children. I expected the four obvious ones, I didn't expect the five text nodes that are interleaved. |
I see. So this issue specifically asked about trimming whitespace off the very front of the string and the very end using |
Heh, I got confused because someone had set Sorry about that. Yes, this is fine. I retract my comments :) |
New line characters at the start and end of the
html
string create text nodes. Should we just trim the string to remove these? I don't see any reason you would purposefully want those start and end text nodes myself.The text was updated successfully, but these errors were encountered: