yoshuawuyts / html

Type-safe HTML support for Rust
Apache License 2.0
247 stars 7 forks source link

Can't place text sourcecode in html <script> element #41

Closed jdonszelmann closed 1 year ago

jdonszelmann commented 1 year ago

Here I am again Yosh :P

One other thing I ran into when converting my code, is that I couldn't just dump js sourcecode in html easily. Sure, I can make a separate file and set src=file.js, but in my case it's actually quite convenient to put everything together. The sourcecode is generated anyway (and I am aware of the security problems that can give, but that genuinely isn't important in my case).

I would like to be able to do Script::builder().text("let a = 3;").build() for example. Even if that doesn't statically check my javascript, which would of course be the end goal on a scale of awesomeness.

In any case, it might be nice to have some kind of way to build custom html, so these kinds of edgecases at least have an escape hatch to solve them with. Maybe those would be unsafe functions, I don't know, but make it at least theoretically possible to insert arbitrary text. What would you think of that?

yoshuawuyts commented 1 year ago

It seems that all that's missing from ScriptBuilder for this to work is the ability to append a "text" child, is that right?

yoshuawuyts commented 1 year ago

We probably need to hard-code the script element to be able to take text here: https://github.com/yoshuawuyts/html/blob/main/crates/html-bindgen/src/merge/mod.rs#L107

jdonszelmann commented 1 year ago

It seems that all that's missing from ScriptBuilder for this to work is the ability to append a "text" child, is that right?

Correct

jdonszelmann commented 1 year ago

❤️