Skip to content

Instantly share code, notes, and snippets.

@favila
Created August 22, 2015 00:31
Show Gist options
  • Save favila/689edb8b6c7b1303fa1a to your computer and use it in GitHub Desktop.
Save favila/689edb8b6c7b1303fa1a to your computer and use it in GitHub Desktop.
Wrap-highlighted, for splitting strings with elasticsearch highlighting.
(defn wrap-highlighted
"Return a vector of string parts where highlighted runs are replaced with (f highlighted-string)."
[f s]
(->> (re-seq #"<em>(.+?)</em>|.+?(?=<em>|$)" s)
(map (fn [[all highlighted]]
(if (nil? highlighted)
all
(f highlighted))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment