method
highlight
v6.0.0 -
Show latest stable
-
0 notes -
Class: ActionView::Helpers::TextHelper
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (-1)
- 2.0.3 (38)
- 2.1.0 (-1)
- 2.2.1 (26)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-3)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-26)
- 4.1.8 (0)
- 4.2.1 (26)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (24)
- 5.1.7 (0)
- 5.2.3 (2)
- 6.0.0 (0)
- 6.1.3.1 (1)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (26)
- 7.1.3.4 (0)
- What's this?
highlight(text, phrases, options = {})
public
Highlights one or more phrases everywhere in text by inserting it into a :highlighter string. The highlighter can be specialized by passing :highlighter as a single-quoted string with \1 where the phrase is to be inserted (defaults to ‘<mark>1</mark>’) or passing a block that receives each matched term. By default text is sanitized to prevent possible XSS attacks. If the input is trustworthy, passing false for :sanitize will turn sanitizing off.
highlight('You searched for: rails', 'rails') # => You searched for: <mark>rails</mark> highlight('You searched for: rails', /for|rails/) # => You searched <mark>for</mark>: <mark>rails</mark> highlight('You searched for: ruby, rails, dhh', 'actionpack') # => You searched for: ruby, rails, dhh highlight('You searched for: rails', ['for', 'rails'], highlighter: '<em>\1</em>') # => You searched <em>for</em>: <em>rails</em> highlight('You searched for: rails', 'rails', highlighter: '<a href="search?q=\1">\1</a>') # => You searched for: <a href="search?q=rails">rails</a> highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) } # => You searched for: <a href="search?q=rails">rails</a> highlight('<a href="javascript:alert(\'no!\')">ruby</a> on rails', 'rails', sanitize: false) # => <a href="javascript:alert('no!')">ruby</a> on <mark>rails</mark>