但是,例如,如果我有一个带有“pãodequeijo”文本的记录并搜索“pao de queijo”,则返回记录,但不突出显示IExt.同样,如果我搜索“pÃodede queijo”,则会返回记录但不会正确突出显示.
我的代码很简单:
<%= highlight(result_pessoa.observacoes,search_string,'<span ></span>') %>解决方法 我刚刚向Rails提交了补丁,解决了这个问题.
http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3593-patch-support-for-highlighting-with-ignoring-special-chars
# Highlights one or more +phrases+ everywhere in +text+ by inserting it into # a <tt>:Highlighter</tt> string. The Highlighter can be specialized by passing <tt>:Highlighter</tt> # as a single-quoted string with where the phrase is to be inserted (defaults to # '<strong ></strong>') # # ==== Examples # highlight('You searched for: rails','rails') # # => You searched for: <strong >rails</strong> # # highlight('You searched for: ruby,rails,dhh','actionpack') # # => You searched for: ruby,dhh # # highlight('You searched for: rails',['for','rails'],:Highlighter => '<em></em>') # # => You searched <em>for</em>: <em>rails</em> # # highlight('You searched for: rails','rails',:Highlighter => '<a href="search?q="></a>') # # => You searched for: <a href="search?q=rails">rails</a> # # highlight('Šumné dIEvčatá',['šumňe','dIEvca'],:ignore_special_chars => true) # # => <strong >Šumné</strong> <strong >dIEvča</strong>tá # # You can still use <tt>highlight</tt> with the old API that accepts the # +Highlighter+ as its optional third parameter: # highlight('You searched for: rails','<a href="search?q="></a>') # => You searched for: <a href="search?q=rails">rails</a> def highlight(text,phrases,*args) options = args.extract_options! unless args.empty? options[:Highlighter] = args[0] || '<strong ></strong>' end options.reverse_merge!(:Highlighter => '<strong ></strong>') 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/,'[^\x00-\x7F]*') end highlighted = haystack.gsub(/(#{match})(?!(?:[^<]*?)(?:["'])[^<>]*>)/i,options[:Highlighter]) highlighted = highlighted.mb_chars.normalize(:kc) if options[:ignore_special_chars] highlighted end end总结
以上是内存溢出为你收集整理的ruby-on-rails – 如何忽略高亮功能中的重音全部内容,希望文章能够帮你解决ruby-on-rails – 如何忽略高亮功能中的重音所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)