Comments (7)
Woah.. wait a second.. this might be possible right now. dtolnay/proc-macro2#166
Doing some reading ...
from percy.
@dbrgn started working on this - should have a PR ready this week if you can take a look
from percy.
@chinedufn fantastic, exactly what I'd intuitively expect! :)
from percy.
Here's how we're able to parse text without needing quotation marks
percy/crates/html-macro/src/tag.rs
Line 75 in 0af49f7
Basically if we come across a token and it doesn't look like anything else (a tag.. attributes.. etc) then we assume it is text.
When parsing tokens from the compiler we have no idea how much spacing was around the token. We just get raw tokens.
So when we're building a string of text we just insert space between tokens ourselves:
percy/crates/html-macro/src/tag.rs
Lines 202 to 204 in 0af49f7
As you see in that code we are only inserting a space after a token if it isn't the first text token in the batch of text.
In your example above Hello
and World
are both the first (and only) text tokens in the batch of text tokens that we see so neither of them is getting any space in front of them.
One thing that would really help here is being able to know the start and end columns of each token
https://docs.rs/proc-macro2/0.4.24/proc_macro2/struct.Span.html#method.start
This way we could look at the two neighboring tokens and know whether or not we need to insert a space character.
Unfortunately this feature of spans hasn't stabilized and I'm not sure if/when it will.
Potential options in the meantime...
-
Always insert space before and after text tokens. This would mean that if you really didn't want a space between an image and some text after it there would be .a space anyway... but maybe that's a trade-off that we can mark for now.
-
Add support for literals
html! { <div>"This will properly be parsed "</div> }
- I want to do this regardless because of #69
- Remove support for un-quoted text until span starts / ends stabilize
- fewer surprises but also much less ergonomic IMO. I don't like this and would rather have this bit of sometimes unexpected (on the first and last word in a sequence of text) behavior than throw away the ergonomics here.
Your thoughts?
from percy.
Supporting literals sounds like a good idea!
I'm not sure about un-quoted text to be honest. It's strange to have two ways to declare text nodes, but on the other hand I think it's fine as long as the differences are documented (i.e. "white-space is collapsed").
from percy.
Hmm I'm thinking that ideally we'd support all ways that someone might try to create things.
So the problem here is less about having two ways and more about having a way that might behave in a way that you don't expect sometimes.
(As always, just my thoughts, very open to being wrong!!)
I can try to figure out where we can follow the progress of stabilization and in the meantime add literal support.
Let me know if you have something different in mind!
from percy.
Alright all of the test cases are passing and can be seen here
https://github.com/chinedufn/percy/blob/text-space/crates/html-macro-test/src/text.rs
Will need to do some refactoring / clean up of the html-macro and then we'll be good to go!
from percy.
Related Issues (20)
- How alive is this project? HOT 3
- Use request_animation_frame from rust instead of Global Js call for update view HOT 3
- Free hosting? HOT 5
- Sub-routes not working? HOT 1
- Bash files in examples to rust-script? HOT 5
- Curly braces for value interpolation HOT 1
- Implement Performance Metrics HOT 2
- Implement a Formatting Tool HOT 2
- Consider Pure JS Transpilation HOT 2
- FYI: branding/naming clash HOT 1
- Crate renames HOT 1
- Docs: Broken CSS HOT 1
- Broken tests in html-macro 0.7.0 and 0.7.1 HOT 4
- Building nojs-first applications (and some thoughts about an isomorphic data layer) HOT 1
- Free Hosting for Demos HOT 1
- Allow Support for multiple parameters in `JSX` syntax HOT 4
- Spaces removed when isomorphic app is hydrated HOT 3
- File referred to in documentation doesn't exist
- Fix parenthesized blocks in html macro
- Panic happened in /allocator/free_list.rs that `new_page == 0` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from percy.