Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Html text without the need of literal strings #16

Open
pepsighan opened this issue Oct 4, 2018 · 6 comments
Open

Html text without the need of literal strings #16

pepsighan opened this issue Oct 4, 2018 · 6 comments
Labels
enhancement New feature or request

Comments

@pepsighan
Copy link
Owner

html! macro uses literal strings to define texts which is quite cumbersome.

html! {
  "Hello World!"
}

It would be HTML like if we could lift this requirement.

html! {
  Hello World!
}

But to implement that we need to get location info from Spans of proc-macro2 which is under procmacro2_semver_exempt. So, we'll need to wait on that for the time being.

@pepsighan pepsighan added the enhancement New feature or request label Oct 4, 2018
@davidhewitt
Copy link

Mmm I have been playing with web-sys too, trying to build something similar to Ruukh :). I ended up writing a parser for html in nom, which works quite well except I can see it's not going to parse rust code inside { }'s very easily...

I wonder if we make some noise in dtolnay/syn#406 whether there's much hope on that becoming stable

@pepsighan
Copy link
Owner Author

@davidhewitt Yeah, plugging nom with syn is going to be difficult and also preserving Span information is of utmost importance so that we can report errors.
syn is not the one to stabilize line informations, I think it's proc-macro2.

@limira
Copy link

limira commented Oct 5, 2018

Hi @csharad, I don't know how feasible to implement this in your project. I tried this with my own project, but finally I prefer strings in "..." than not. There are only two more characters to type, and also you don't have to invest your time trying to implement it. My reason is that in a large code in html!{...}, if you put strings in "...", with the help of the editor highlighting, they stand out clearly. It helps to distinct/spot out items more easily. Without the "...", editors highlight them as identifiers, punct... which they are not, make it hard for to find out things we want.

@davidhewitt
Copy link

davidhewitt commented Oct 5, 2018

@limira while I definitely see the benefits of the approach you've taken in Simi, my own preference is to have a syntax as close to HTML as possible. Though I concede that to support nice highlighting inside the html! macro will then need extra editor grammar added, I think sticking to HTML syntax gives users of the api a sense of familiarity.

I suspect this is one of those things that's a matter of everyone's individual preferences; both styles have their merits!

@limira
Copy link

limira commented Oct 6, 2018

@davidhewitt, yeah, because I don't want to stay close to HTML hence I gave up the idea more easily. If you want to stick with HTML, in a .rs file, (along with the highlighting) you should consider about auto close tag. I mean when users type <div> then </div> should be added automatically for the user to feel it's home.

@pepsighan
Copy link
Owner Author

@limira As @davidhewitt has said, html! macro will try to keep the syntax as close to HTML as possible for familiarity reasons.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants