Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've just submitted a patch to Rails thats solves this.</p> <p><a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3593-patch-support-for-highlighting-with-ignoring-special-chars" rel="nofollow noreferrer">http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3593-patch-support-for-highlighting-with-ignoring-special-chars</a></p> <pre><code> # Highlights one or more +phrases+ everywhere in +text+ by inserting it into # a &lt;tt&gt;:highlighter&lt;/tt&gt; string. The highlighter can be specialized by passing &lt;tt&gt;:highlighter&lt;/tt&gt; # as a single-quoted string with \1 where the phrase is to be inserted (defaults to # '&lt;strong class="highlight"&gt;\1&lt;/strong&gt;') # # ==== Examples # highlight('You searched for: rails', 'rails') # # =&gt; You searched for: &lt;strong class="highlight"&gt;rails&lt;/strong&gt; # # highlight('You searched for: ruby, rails, dhh', 'actionpack') # # =&gt; You searched for: ruby, rails, dhh # # highlight('You searched for: rails', ['for', 'rails'], :highlighter =&gt; '&lt;em&gt;\1&lt;/em&gt;') # # =&gt; You searched &lt;em&gt;for&lt;/em&gt;: &lt;em&gt;rails&lt;/em&gt; # # highlight('You searched for: rails', 'rails', :highlighter =&gt; '&lt;a href="search?q=\1"&gt;\1&lt;/a&gt;') # # =&gt; You searched for: &lt;a href="search?q=rails"&gt;rails&lt;/a&gt; # # highlight('Šumné dievčatá', ['šumňe', 'dievca'], :ignore_special_chars =&gt; true) # # =&gt; &lt;strong class="highlight"&gt;Šumné&lt;/strong&gt; &lt;strong class="highlight"&gt;dievča&lt;/strong&gt;tá # # You can still use &lt;tt&gt;highlight&lt;/tt&gt; with the old API that accepts the # +highlighter+ as its optional third parameter: # highlight('You searched for: rails', 'rails', '&lt;a href="search?q=\1"&gt;\1&lt;/a&gt;') # =&gt; You searched for: &lt;a href="search?q=rails"&gt;rails&lt;/a&gt; def highlight(text, phrases, *args) options = args.extract_options! unless args.empty? options[:highlighter] = args[0] || '&lt;strong class="highlight"&gt;\1&lt;/strong&gt;' end options.reverse_merge!(:highlighter =&gt; '&lt;strong class="highlight"&gt;\1&lt;/strong&gt;') if text.blank? || phrases.blank? text else haystack = text.clone match = Array(phrases).map { |p| Regexp.escape(p) }.join('|') if options[:ignore_special_chars] haystack = haystack.mb_chars.normalize(:kd) match = match.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]+/n, '').gsub(/\w/, '\0[^\x00-\x7F]*') end highlighted = haystack.gsub(/(#{match})(?!(?:[^&lt;]*?)(?:["'])[^&lt;&gt;]*&gt;)/i, options[:highlighter]) highlighted = highlighted.mb_chars.normalize(:kc) if options[:ignore_special_chars] highlighted end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload