summaryrefslogtreecommitdiff
path: root/src/clarktown/parsers/italic.clj
diff options
context:
space:
mode:
authorAsko Nõmm <asko@bien.ee>2021-12-04 17:33:28 -0300
committerAsko Nõmm <asko@bien.ee>2021-12-04 17:33:28 -0300
commit8a5e868098005401ff7cba45ec50e9c6612550f4 (patch)
tree642f7d01e4c3fd8c5645dab0053aef30b093a57e /src/clarktown/parsers/italic.clj
parent790dec05b269d13dbdf73fa645fc67e2d5f286f9 (diff)
Add italic text renderer
Diffstat (limited to 'src/clarktown/parsers/italic.clj')
-rw-r--r--src/clarktown/parsers/italic.clj18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/clarktown/parsers/italic.clj b/src/clarktown/parsers/italic.clj
new file mode 100644
index 0000000..5b90d12
--- /dev/null
+++ b/src/clarktown/parsers/italic.clj
@@ -0,0 +1,18 @@
+(ns clarktown.parsers.italic
+ (:require
+ [clojure.string :as string]))
+
+
+(defn render
+ "Renders all occuring italic text as italic."
+ [block]
+ (loop [block block
+ matches (-> (re-seq #"_.*?_" block)
+ distinct)]
+ (if (empty? matches)
+ block
+ (let [match (first matches)
+ value (subs match 1 (- (count match) 1))
+ replacement (str "<em>" value "</em>")]
+ (recur (string/replace block match replacement)
+ (drop 1 matches))))))