module Padrino::Helpers::FormatHelpers
def highlight(text, words, *args)
- Api: - public
Returns:
-
(String)
- The text with the words specified wrapped with highlighted spans.
Options Hash:
(**options)
-
:highlighter
(String
) --
Parameters:
-
options
(Hash
) -- -
words
(String
) -- -
text
(String
) --
Overloads:
-
highlight(text, words, options={})
def highlight(text, words, *args) options = args.extract_options! options.reverse_merge!(:highlighter => '<strong class="highlight">\1</strong>') if text.blank? || words.blank? text else match = Array(words).map { |p| Regexp.escape(p) }.join('|') text.gsub(/(#{match})(?!(?:[^<]*?)(?:["'])[^<>]*>)/i, options[:highlighter]) end end