Merge pull request #3592 from avakhov/av-highlight-regexp
Fix and simplify highlight regexp
This commit is contained in:
commit
bdd76fb5e3
@ -120,7 +120,7 @@ def highlight(text, phrases, *args)
|
||||
text
|
||||
else
|
||||
match = Array(phrases).map { |p| Regexp.escape(p) }.join('|')
|
||||
text.gsub(/(#{match})(?!(?:[^<]*?)(?:["'])[^<>]*>)/i, options[:highlighter])
|
||||
text.gsub(/(#{match})(?![^<]*?>)/i, options[:highlighter])
|
||||
end.html_safe
|
||||
end
|
||||
|
||||
|
@ -194,6 +194,10 @@ def test_highlight_with_html
|
||||
"<p>This is a <strong class=\"highlight\">beautiful</strong> <a href=\"http://example.com/beautiful#top?what=beautiful%20morning&when=now+then\">morning</a>, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
|
||||
highlight("<p>This is a beautiful <a href=\"http://example.com/beautiful\#top?what=beautiful%20morning&when=now+then\">morning</a>, but also a beautiful day</p>", "beautiful")
|
||||
)
|
||||
assert_equal(
|
||||
"<div>abc <b>div</b></div>",
|
||||
highlight("<div>abc div</div>", "div", :highlighter => '<b>\1</b>')
|
||||
)
|
||||
end
|
||||
|
||||
def test_excerpt
|
||||
|
Loading…
Reference in New Issue
Block a user