Fork me on GitHub
#rum
<
2018-08-07
>
grounded_sage03:08:21

Is there a simple way to escape html? I seem to be overlooking something in Rum I think

grounded_sage03:08:38

I'd like to use an svg

<svg width="96" height="96" viewBox="0 0 96 96" fill="none" xmlns="http://www.w3.org/2000/svg">}}]])
<circle cx="32.5" cy="32.5" r="31" transform="translate(16)" stroke="#BF9C8C" stroke-width="3"/>
<circle cx="32.5" cy="32.5" r="31" transform="translate(16 31)" stroke="#BF9C8C" stroke-width="3"/>
<circle cx="32.5" cy="32.5" r="31" transform="translate(0 15)" stroke="#BF9C8C" stroke-width="3"/>
<circle cx="32.5" cy="32.5" r="31" transform="translate(31 15)" stroke="#BF9C8C" stroke-width="3"/>
</svg>
with no manual escaping or converting to hiccup syntax.

mattly04:08:23

is that code in a variable somewhere?

mattly04:08:19

like, as a string?

mattly04:08:47

you can do [:div {:dangerouslySetInnerHTML {:__html my-svg}}]

mattly04:08:00

this is more of a react thing

mattly04:08:15

one does not simply splice a string into the virtual dom

mattly04:08:47

a better method would be to either

mattly04:08:58

1. make the svg available over HTML and use an img tag

mattly04:08:16

2. base64-encode it in CSS and have it be a background-image on some id or class

grounded_sage05:08:21

It appears to exhibit the same behaviour whether in a def or or inline. I did to it in a previous project (with manual escaping) as I was using inline svg and symbols to split the svg into reusable components that were composed in different ways throughout the page. It’s better for performance as it’s streamed with HTML and reduces extra requests.

euccastro23:08:44

@grounded_sage why not convert them to hiccup syntax? you could still render them and compose them at the server side. also, if you're going to have a react app, then you're going to ship your JS code anyway, so you could alternatively build your SVG there and it wouldn't cost any extra requests