developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.73k stars 170 forks source link

Support for something like dangerouslySetInnerHTML #220

Closed aaronbieber closed 2 years ago

aaronbieber commented 2 years ago

I have a project where I am using HTM exclusively to build my components, and I have a component that needs to output some Markdown as HTML. I control this data, so I am not concerned about security risks in the Markdown to HTML conversion, but I can't find a way to output "raw HTML" from a component using HTM.

I've tried a number of React-oriented solutions, including markdown-it-jsx and react-markdown, but either they didn't work with Preact properly or just output the encoded HTML.

The easiest way around this is to have a back door through h() that passes HTML text straight through, like React does with dangerouslySetInnerHTML.

I'm very open to the notion that there is some way to do this that I am missing.

Kanaye commented 2 years ago

dangerousSetInnerHTML is in htms "eyes" just a property, so it depends on the used rendering library to support it. Sounds like you're using it with preact and preact supports it, even with htm: https://codesandbox.io/s/suspicious-parm-kyubbc

aaronbieber commented 2 years ago

I believe I got some syntax wrong and will try again; @Kanaye's example obsoletes this issue so I'll close it.