-
Notifications
You must be signed in to change notification settings - Fork 225
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 #22 (extra lines) #32
Conversation
b06d3e5
to
6d7867c
Compare
6d7867c
to
fa0df6d
Compare
Thanks for the pull request @AliSoftware, for a few reasons I don't like this implementation:
To solve this, instead the following rule should be applied:
Example 1
Would result in: Token.Text("1\n")
Token.Block("foo")
Token.Text("2\n") Example 2
Would result in: Token.Text("1\n")
Token.Text("this is awesome:")
Token.Block("foo")
Token.Text("\n - 2\n") Note: The new line at the end of the Instead of doing this work in the individual parser level, I think this should be moved into the lexer and the lexer should ensure that any text token after a block token doesn't start with CR/LF. While currently this would be difficult to implement due how it's currently implemented. I do have some local changes I'm working on which removes the use of regex for it's own character position to be able to construct source maps to allow the errors to clearly state which part of the template caused them (#28). Once this change is done, it would be fairly easily to remove all whitespace and trailing new lines for any blocks. I hope to finish the source maps today and I can make an alternative PR to implement this on-top of the source-map parser inside the lexer itself. |
That was in fact kinda intended, because I think not every Node would want to trim the CRLFs. But I didn't like it either.
Totally agree, implementing this rule would be much better. In the meantime, I'll try to rework #33 to apply |
Would you see any problems with my proposed solution where it would unintentionally trim characters that some node's wouldn't like? |
Well imagine I create an
I expect it to be rendered like this:
Isn't there a risk that with your proposed implementation, the CRLFs after every `{% lowercase x %} will be trimmed then? |
Note: agreed that And a more concrete example is the use of Example
Should generate:
But your solution will generate:
Probably only blocks that expect an end block would expect to trim CRLFs I think. But you can't know that during lexing, can you? |
Sorry for not getting to this sooner. Let me have a think on this one and get back to you. |
Any updates on this? Is a valid solution stripping the whitespace and newlines only when it's a control flow block (e.g. if and for) |
@yonaskolb This is something I'm going to get in before Stencil 1.0. |
Thanks for the effort here @AliSoftware. I'd like to go with the alternative design in #92 because this allows the template author to control how it is handled. @AliSoftware Do you have any major concerns with #92? |
Add said in #85 I'm in agreement with a solution (also seen in other templating languages) of allowing the user to enable lead and tail trimming per tag invocation using |
Replaced by #287 |
Fix #22