Escaping HTML in `content` transform

21 views
Skip to first unread message

xavi

unread,
Sep 9, 2014, 6:46:28 AM9/9/14
to enf...@googlegroups.com
Just found out that differently than Enlive's `content` transform, Enfocus' `content` doesn't escape HTML, and in the source code for `enfocus.core/content` transform there's this TODO...
;;TODO need to figure out how to make sure this stay just as
;;text and not convert to html.

I found this solution http://stackoverflow.com/a/5251551 , which can be translated to ClojureScript as...

(defn escape-html
  [s]
  (let [pre (.createElement js/document "pre")
        text (.createTextNode js/document s)]
    (.appendChild pre text)
    (.-innerHTML pre)))

I'm using this successfully in an app I'm working on, maybe could be integrated into Enfocus' `content` transformation.

Cheers
Xavi

Creighton Kirkendall

unread,
Sep 10, 2014, 6:31:23 AM9/10/14
to Enfocus
Xavi,
That is a slick solution.  I will have to test out how performant it is but it may do the trick.  Thanks.

Creighton

--

---
You received this message because you are subscribed to the Google Groups "Enfocus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to enfocus+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages