Created
August 22, 2015 00:31
-
-
Save favila/689edb8b6c7b1303fa1a to your computer and use it in GitHub Desktop.
Wrap-highlighted, for splitting strings with elasticsearch highlighting.
This file contains hidden or 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 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