Fork me on GitHub
#clojurescript
<
2023-09-05
>
Jacob Doran13:09:48

Hi, I have a bit of a simple question. I'm using lilactown/helix to write a blog site, I'd like to put in a html character &rarr; but I only get it as raw text not a rendered figure. I've tried unicode points as well to no effect. Here's the component. ($ link/link {:href href :class-name "text-base font-medium leading-6 text-primary-500 hover:text-primary-600 dark:hover:text-primarf-400" :aria-label (str "Link to " title)} "Learn more &rarr;") Any ideas on how to render the figure, or escape the text? Not too sure what the approach here is.

p-himik13:09:11

Just in case - if it's a more or less static blog then Helix (as well as the underlying React) is likely an overkill and something like a static website generator would be a better fit. As for your actual question - nowadays it isn't that much of a problem to just include the symbol in your sources directly: "Learn more →".

❤️ 4
Jacob Doran13:09:29

Oh it's definitely overkill, but it makes me happy ^^ As for the arrow. Putting it in directly worked beautifully thanks a bunch.

phill15:09:13

The key thing is that evidently your tool "escapes" the string content, thereby making an equivalent presentation once the browser interprets the HTML. This is considered a Very Good Thing because it inhibits injection attacks. As a result, your responsibility (as the programmer) is to provide an accurate Clojure string, NOT HTML. Therefore pasting the arrow, literally, works. You also have another option: If you want a 7-bit-clean source code, you can use the usual \uXXXX kind of notation (for Clojure strings) to insert the arrow.

hifumi12319:09:23

I am surprised nobody has told you about goog.string/unescapeEntities yet

hifumi12319:09:26

It should be sufficient to (require '[goog.string :as gstr]) then make the link's child (gstr/unescapeEntities "Learn more &rarr;")

p-himik20:09:57

That function is nasty, I'd avoid it when at all possible.