summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAsko Nõmm <asko@bien.ee>2021-12-04 17:33:35 -0300
committerAsko Nõmm <asko@bien.ee>2021-12-04 17:33:35 -0300
commitc4f79e446b3e88f2744e413b6927415831f56400 (patch)
treed4874ee972d87a9a4590b677720a381f2c87b018 /src
parent8a5e868098005401ff7cba45ec50e9c6612550f4 (diff)
Add inline code renderer
Diffstat (limited to 'src')
-rw-r--r--src/clarktown/parsers/inline_code.clj21
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 #"&" "&amp;")
+ (string/replace #"<" "&lt;")
+ (string/replace #">" "&gt;"))
+ replacement (str "<code>" value "</code>")]
+ (recur (string/replace block match replacement)
+ (drop 1 matches))))))