-
-
Save yedi/59f934b4f83ac396741c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn word-span [idx word] ; function that will render the correct color based on the idx | |
(d/span #js {:style #js {:color "red"}} word)) | |
(defn text-spans [text] | |
(let [tokens (map (partial apply str) | |
(partition-by #{\space \tab \newline} text))] | |
(loop [tokens tokens | |
idx 0 | |
spans '()] | |
(cond | |
(empty? tokens) (reverse spans) | |
(re-matches #"\s" (first tokens)) | |
(recur (rest tokens) | |
idx | |
(conj spans (d/span nil (first tokens)))) | |
:else (recur (rest tokens) | |
(inc idx) | |
(conj spans (word-span idx (first tokens)))))))) | |
(defn analysis-view [data owner] | |
(reify | |
om/IRender | |
(render [this] | |
(apply d/div nil | |
(text-spans (get-in data [:text])))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment