Fork me on GitHub
#reagent
<
2020-01-30
>
simongray13:01:42

Anybody know if there is a quick way to represent HTML comments in reagent hiccup?

p-himik13:01:27

The only way is probably via dangerouslySetInnerHTML, which also requires knowing the parent element.

simongray13:01:08

ok, thanks for the quick reply!

p-himik13:01:25

Seems like you could also create a custom component for that: https://stackoverflow.com/a/41131326/564509 A little bit more involved than just using Hiccup.

simongray14:01:41

@U2FRKM4TW Yeah, I also found that same resource after googling it. Think I’m gonna attempt something like that 😉

p-himik14:01:14

Just out of interest - why do you need HTML comments at all?

simongray14:01:54

@U2FRKM4TW I need to embed XML inside an HTML page as HTML custom elements and want to be as faithful to the source as possible. It’s not really necessary, I guess, but why not? Kind of a fun exercise ;)

p-himik14:01:08

I see. Is the original form of the XML string or Hiccup?

simongray14:01:54

it’s an XML string that I’m parsing with the DOM api and then converting to hiccup. I have a bunch of linguists manually transcribing old letters from the 1930s into this XML format and I’m tasked with creating a reader for it in the browser.

p-himik15:01:36

So you have a "string->DOM api->hiccup->React elements" conversion. You can probably use dangerouslySetInnerHTML on the parent where you embed the XML and avoid any conversion at all. That is, unless you also transform/process the XML data in Clojure[Script].

lilactown17:01:06

be careful using dangerouslySetInnerHTML with non-static things. a compromise in your db or other area of your site could lead to XSS exploits

👍 4