diff options
| author | Asko Nõmm <asko@bien.ee> | 2021-12-04 17:33:35 -0300 |
|---|---|---|
| committer | Asko Nõmm <asko@bien.ee> | 2021-12-04 17:33:35 -0300 |
| commit | c4f79e446b3e88f2744e413b6927415831f56400 (patch) | |
| tree | d4874ee972d87a9a4590b677720a381f2c87b018 /src/clarktown | |
| parent | 8a5e868098005401ff7cba45ec50e9c6612550f4 (diff) | |
Add inline code renderer
Diffstat (limited to 'src/clarktown')
| -rw-r--r-- | src/clarktown/parsers/inline_code.clj | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/clarktown/parsers/inline_code.clj b/src/clarktown/parsers/inline_code.clj new file mode 100644 index 0000000..b4323d7 --- /dev/null +++ b/src/clarktown/parsers/inline_code.clj @@ -0,0 +1,21 @@ +(ns clarktown.parsers.inline-code + (:require + [clojure.string :as string])) + + +(defn render + "Renders all occuring inline code." + [block] + (loop [block block + matches (-> (re-seq #"\`.*?\`" block) + distinct)] + (if (empty? matches) + block + (let [match (first matches) + value (-> (subs match 1 (- (count match) 1)) + (string/replace #"&" "&") + (string/replace #"<" "<") + (string/replace #">" ">")) + replacement (str "<code>" value "</code>")] + (recur (string/replace block match replacement) + (drop 1 matches)))))) |
