:  ~ 1 min read

Fixing the search

First of all, I changed the <search-mark> tag to <span class='search-mark'>. Secondly, I'm properly adding the search-mark to all occurrences of the searched term, instead of only the first (silly me). Lastly, I search the content again to remove the search-mark from inside hrefs:

start_index = content.downcase.index(w)
end_index = start_index + w.length
original_occurrence = content[start_index..end_index - 1]
content.gsub!(/#{original_occurrence}/i, '<span class=\'search-mark\'>\0</span>')
content.scan(/href=".*?"/).each do |s|
  edited_link = s.gsub('<span class=\'search-mark\'>', '')
  edited_link.gsub!('</span>', '')
  content.gsub!(s, edited_link)