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

Is there a way to not insert a line feed like ejs? #89

Closed
muukii opened this issue Dec 30, 2016 · 4 comments
Closed

Is there a way to not insert a line feed like ejs? #89

muukii opened this issue Dec 30, 2016 · 4 comments
Milestone

Comments

@muukii
Copy link

muukii commented Dec 30, 2016

Is there a way to not insert a line feed like ejs? -%>

@kylef
Copy link
Collaborator

kylef commented Jan 5, 2017

Not currently, but this is one of the things I'd like to support in Stencil 1.0. Haven't given though on the best way to solve this, potentially using - to indicate how whitespace and new lines should be treated just like Jinja2 or ejs.

The are many behaviours using both + and - to control whitespace in Jinja2 which you can find in their documentation http://jinja.pocoo.org/docs/dev/templates/#whitespace-control. I have been trying to keep the template language aligned with Jinja2 and Django as much as possible so the language is consistent with these similar existing language.

There has been previous discussion in #22, #32 and #85. I didn't like some of the other solutions because they change the behaviour for all tokens which may not be desired for some types of templates or tokens. For these reasons I was personally leaning towards supporting whitespace/newline control like Jinja2/ejs.

/cc @AliSoftware

@kylef kylef added this to the 1.0.0 milestone Jan 5, 2017
@muukii
Copy link
Author

muukii commented Jan 8, 2017

@kylef
Thank you for your reply.
I understood your idea.
Thank you for considering the correspondence.

@bejar37
Copy link

bejar37 commented Jan 15, 2017

@kylef I started implementing Jinja2 behavior, and I think I'm pretty far along. What I've done so far is parse white-space controlling information ("{%+", "{%-", "-%}", and "+%}") for Block tokens, and used that information when constructing TextNodes during parse-time.

I have this working in "for", "if", and "ifnot" tags (I believe).
Before putting more time into this I want to make sure that you think I'm going down the right path. Some assumptions that I've made:

  • the whitespace control characters "+" and "-" are only significant in Block tokens
  • The only default tags where this makes sense are "if", "ifnot", and "for"
  • Custom tags will have to change in order to opt-in to the whitespace-respecting behavior.

Let me know if you'd rather me just comment on this in a PR.

Thanks, and sorry if this is coming out of left field! Here's my implementation so far: https://github.com/bejar37/Stencil/tree/NewlineBehavior

/cc @AliSoftware @muukii

@tcldr
Copy link

tcldr commented Mar 7, 2019

Would love to see this. I currently have some macros which I've had to define on a single line. (Think automated generation of function parameters.) This addition would complete the picture, for me.

@djbe djbe modified the milestones: 1.0.0, 0.15.0 Jul 28, 2022
@djbe djbe closed this as completed Jul 29, 2022
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

No branches or pull requests

5 participants