From 17b81ba52cfb25e85c5deba8d5397de68f1fa6a6 Mon Sep 17 00:00:00 2001 From: Daniel Compton Date: Thu, 25 Jan 2018 23:18:32 +1300 Subject: [PATCH] XML encode # character in SVGs Fixes #130. See also https://stackoverflow.com/a/38459219. --- src/day8/re_frame/trace/utils/macros.clj | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/day8/re_frame/trace/utils/macros.clj b/src/day8/re_frame/trace/utils/macros.clj index 03ee813..569340a 100644 --- a/src/day8/re_frame/trace/utils/macros.clj +++ b/src/day8/re_frame/trace/utils/macros.clj @@ -1,10 +1,18 @@ (ns day8.re-frame.trace.utils.macros - (:require [clojure.java.io :as io])) + (:require [clojure.java.io :as io] + [clojure.string :as str])) (defmacro slurp-macro - "Reads a file as a string. Slurp is wrapped in a macro so it can interact with local files before clojurescript compilation." + "Reads a file as a string. Slurp is wrapped in a macro so it can interact with local files before clojurescript compilation. + #'s are replaced with %23 for URL encoding." + ;; For reasons unknown (to me), browsers don't like URL encoding the entire string. + ;; I suspect XML encoding the attributes is the correct way to do this, but + ;; #'s are the problem here, so we so we do surgery on the one problematic symbol. [path] - (slurp (io/resource path))) + (str/replace + (slurp (io/resource path)) + "#" + "%23")) (defmacro with-cljs-devtools-prefs [prefs & body] `(let [previous-config# (devtools.prefs/get-prefs)