Skip to content

Instantly share code, notes, and snippets.

@yedi
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yedi/59f934b4f83ac396741c to your computer and use it in GitHub Desktop.
Save yedi/59f934b4f83ac396741c to your computer and use it in GitHub Desktop.
(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