diff options
Diffstat (limited to 'src/clarktown/parsers/link_and_image.clj')
| -rw-r--r-- | src/clarktown/parsers/link_and_image.clj | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/clarktown/parsers/link_and_image.clj b/src/clarktown/parsers/link_and_image.clj index 3dbbac7..fb8ad31 100644 --- a/src/clarktown/parsers/link_and_image.clj +++ b/src/clarktown/parsers/link_and_image.clj @@ -3,18 +3,24 @@ [clojure.string :as string])) +(defn encode-href + [href] + (-> href + (string/replace "_" "_"))) + + (defn render "Renders all occurring links and images." [block _] (loop [block block - matches (-> (re-seq #"\!?\[(\w+( \w+|\.|\,)*)\]\((.*?)\)" block) + matches (-> (re-seq #"\!?\[(\w+( \w+)*)\]\((.*?)\)" block) distinct)] (if (empty? matches) block (let [[whole-match label _ href] (first matches) image? (string/starts-with? whole-match "!") - image (str "<img src=\"" href "\" alt=\"" label "\">") - link (str "<a href=\"" href "\">" label "</a>")] + image (str "<img src=\"" (encode-href href) "\" alt=\"" label "\">") + link (str "<a href=\"" (encode-href href) "\">" label "</a>")] (recur (if image? (string/replace block whole-match image) (string/replace block whole-match link)) |
