mdoTomofumi Chiba
10/12/2023, 1:23:07 PM

VanJS で dangerous html
https://github.com/vanjs-org/van/discussions/21#discussioncomment-6010860

import van from "./van.js"

const { span, h1, div, form, input, label, button, hr } = van.tags
const add = (base) => (elt) => van.add(base, elt)
const target = document.getElementById("app");

function htmlToElement(html) {
    var template = document.createElement('template');
    html = html.trim(); // Never return a text node of whitespace as the result
    template.innerHTML = html;
    return template.content.firstChild;
}

const s = `<div class="Callout">
  Long-form information about the important content. This text is styled
  as <a href="#core/typography.running-text">"Running text"</a>, so it
  may contain things like headers, links, lists,
  <code class="bp4-code">code</code> etc.
</div>`

const CallOut = htmlToElement(s)

add(app)(
  div(
    h1("Hello"),
    CallOut
  )
)
TweetBlueskyLike