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

Config for blocks without curly braces #22

Open
Zizico2 opened this issue Aug 17, 2022 · 6 comments
Open

Config for blocks without curly braces #22

Zizico2 opened this issue Aug 17, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@Zizico2
Copy link

Zizico2 commented Aug 17, 2022

Let's say I want to have rust code directly inside <script></script>, like Svelte and Vue do for JS. Would this be possible with the current configuration options?

I think this would be implementable if I just went through the TokenStream and added { after every <script> and } before every </script>. Time complexity would go down the gutter though (maybe I could implement this with a map? which is lazy, but still). Maybe a config option to accept blocks directly inside certain tags would be useful. Or a more general Visitor-like API that would allow the insertions of the {/} where needed.

@Zizico2
Copy link
Author

Zizico2 commented Aug 17, 2022

I can take a stab at implementing this if you point me in the general direction

@stoically
Copy link
Owner

Just to be sure: Your goal is to have code looking like e.g.

<script>let key = "value";</script>

and have the element content be parsed as rust block?

@Zizico2
Copy link
Author

Zizico2 commented Aug 17, 2022

Exactly. Could even allow an attribute to toggle that behavior

@stoically
Copy link
Owner

Currently that's not possible. It might be possible to introduce an "element child hook", where you would be responsible to parse starting from the opening <script> tag until and including the </script> tag. That would be a real challenge tho.

I'm curious, why isn't

<script>{ let key = "value"; }</script>

an option in your use case? If it's purely cosmetics, I'd say it isn't worth it.

@stoically
Copy link
Owner

I'll look into the hook either way, might even be possible to hook the whole raw element content.

@stoically stoically added the enhancement New feature or request label Aug 17, 2022
@Zizico2
Copy link
Author

Zizico2 commented Aug 18, 2022

It is 99% cosmetic. And I have it working as is right now. I'd say it's is somewhat semantic too though. Because in the rest of the app, my lib will take the return of the block and render it, assign it to an attribute, etc. I don't care what's inside the block, I only care about it's return. Whereas the block inside script will be handled in a special manner. The difference in syntax would hint at that difference in behavior.

dezren39 pushed a commit to dezren39/syn-rsx that referenced this issue Jul 31, 2023
…-attribute

Feat: add number support in NodeName attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants