Giter VIP home page Giter VIP logo

Comments (7)

chinedufn avatar chinedufn commented on May 15, 2024 1

Woah.. wait a second.. this might be possible right now. dtolnay/proc-macro2#166

Doing some reading ...

from percy.

chinedufn avatar chinedufn commented on May 15, 2024 1

@dbrgn started working on this - should have a PR ready this week if you can take a look

from percy.

dbrgn avatar dbrgn commented on May 15, 2024 1

@chinedufn fantastic, exactly what I'd intuitively expect! :)

from percy.

chinedufn avatar chinedufn commented on May 15, 2024

Here's how we're able to parse text without needing quotation marks

return parse_text_node(&mut input);

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:

if idx != 0 {
text += " ";
}


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...

  1. 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.

  2. Add support for literals html! { <div>"This will properly be parsed "</div> }

  • I want to do this regardless because of #69
  1. 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.

dbrgn avatar dbrgn commented on May 15, 2024

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.

chinedufn avatar chinedufn commented on May 15, 2024

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.

chinedufn avatar chinedufn commented on May 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.