diff options
| author | Asko Nõmm <asko@bien.ee> | 2022-04-19 17:50:19 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@bien.ee> | 2022-04-19 17:50:19 +0300 |
| commit | 52203a49aa544b2c11c96445d8732893160c436b (patch) | |
| tree | 84d7b0e9af92770647643bdf7ddbb898663bd7b8 /src/clarktown/parsers/link_and_image.clj | |
| parent | 059bfa7bd9bfdde0c75646bf1dfc20d23da8a02c (diff) | |
WIP #16
Pretty much done. Needs more testing. And new documentation.
Diffstat (limited to 'src/clarktown/parsers/link_and_image.clj')
| -rw-r--r-- | src/clarktown/parsers/link_and_image.clj | 27 |
1 files changed, 0 insertions, 27 deletions
diff --git a/src/clarktown/parsers/link_and_image.clj b/src/clarktown/parsers/link_and_image.clj deleted file mode 100644 index 3be2efe..0000000 --- a/src/clarktown/parsers/link_and_image.clj +++ /dev/null @@ -1,27 +0,0 @@ -(ns clarktown.parsers.link-and-image - (:require - [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 #"\!?\[([a-zA-Z0-9\-\.\,]+( [a-zA-Z0-9\-\.\,]+)*)\]\((.*?)\)" block) - distinct)] - (if (empty? matches) - block - (let [[whole-match label _ href] (first matches) - image? (string/starts-with? whole-match "!") - 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)) - (drop 1 matches))))))
\ No newline at end of file |
