-
Notifications
You must be signed in to change notification settings - Fork 170
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
(htm + vhtml) How do I insert unescaped HTML from variable? #137
Comments
import htm from "htm";
import vhtml from "vhtml";
const html = htm.bind(vhtml);
const frag = "<p>Hello, World!</p>"
console.log(html`<div>${frag}</div>`);
<div><p>Hello, World!</p></div> edit: Something was wrong (in my computer) and this is apparently not right. |
No framework, I use htm.bind(vhtml) exactly as you've shown. Example: http://dimgel.me/drop/vhtml/7-bug-undefined-tag.html |
Re-uploaded files to show case 2 (previously mistakingly uploaded case 3). Actually, I came to realize that just pure JS string interpolation would be enough for me, I only have to explicitly escape plain texts, like |
Okay, maybe my computer was a little strange :-( Template tag functions get arguments as arrays: so you might have more luck in calling This import htm from "htm";
import vhtml from "vhtml";
const html = htm.bind(vhtml);
const frag = "<p>Hello, World!</p>"
console.log(html`<div>${html([frag])}</div>`); produces: <div><p>Hello, World!</p></div> |
That worked indeed, thank you! :) |
@goranmoomin Here's an example :
Anyway the screenshot above is taken from |
Hello. Trying hml-2.2.1 mini + vhtml-2.1.0 min. Below are few use cases I tried, which demonstrate totally inconsistent behaviour.
Case 1 (good but useless):
Case 2: wrapping ${h} into
<div>
(real use case):Case 3: manually calling html() with wrapping
<div>
(real use case):Case 3a (real example I initially stuck into; it looses
<p>
around "text"):Case 4: manually calling html() without wrapping
<div>
:Case 5: manually calling html() with wrapping
<div>
and variable containing multiple elements:I suppose I do it wrong in case 5, I should wrap multiple
<p>
into some single element, like I do in case 3a. I could also ignore weird<undefined>
elements if it worked correctly otherwise.So, how do I do it correctly, then?
Thanks.
The text was updated successfully, but these errors were encountered: