# This will search and replace multiple terms with an arbitrary string
# but ignore any characters inside angle brackets inside the string
# eg "This is spantastic!" => This is spantastic!
def search_highlight text, phrases
return text if phrases.blank?
phrases.each do |phrase|
phrase = Regexp.escape(phrase)
unless text.nil?
text = text.gsub /((?:\G|>)[^<>]*?)(#{phrase})/i, '\1\2'
end
end
return text
end