ActionView::Helpers::TextHelper
def highlight(text, phrases, options = {}, &block)

Description

Returns the string with the matching parts wrapped in <mark>.

Arguments

Changing a value updates the ERB and HTML.

Wraps the parts that match the phrases argument in <mark>. Text inside tags (the name and attributes of <b>) is not searched. If the :sanitize option is omitted, sanitizes the string before searching, removing tags such as <script>. Since it searches the sanitized string (where & is &amp;), searching for & or amp matches inside &amp;.
A string matches case-insensitively. An array wraps the parts that match any of its elements. A regular expression is used as is, so without the i flag it is case-sensitive: /f\w+/ does not match Fish. An empty string wraps nothing.
options= {}
"<strong>\\1</strong>"
Replaces each match with the given string instead of <mark>\1</mark>, where \1 (and \0) is the matched text, and \2 to \9 are the regular expression's groups, if any. Unlike String#sub, \& and similar are left as is. The matched text is escaped before it is inserted (" becomes &quot;, etc.), leaving already escaped parts such as &amp; as is. The same applies to the default <mark>\1</mark>.
false searches without sanitizing. The returned string is marked html_safe, so tags such as <script> are output as is, without escaping.
Options not listed here are ignored.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview