Skip to content
Snippets Groups Projects
Commit 26992add authored by Douwe Maan's avatar Douwe Maan
Browse files

Make AutolinkFilter smarter about trailing punctuation

parent 4b1b4280
No related branches found
No related tags found
1 merge request!4121WIP: Autolink packages in dependency files like `Gemfile`
Loading
Loading
@@ -26,7 +26,7 @@ module Banzai
# in the generated link.
#
# Rubular: http://rubular.com/r/cxjPyZc7Sb
LINK_PATTERN = %r{([a-z][a-z0-9\+\.-]+://\S+)(?<!,|\.)}
LINK_PATTERN = %r{([a-z][a-z0-9\+\.-]+://\S+)(?<![,."':?!&)<>])}
 
# Text matching LINK_PATTERN inside these elements will not be linked
IGNORE_PARENTS = %w(a code kbd pre script style).to_set
Loading
Loading
Loading
Loading
@@ -130,6 +130,15 @@ describe Banzai::Filter::AutolinkFilter, lib: true do
 
doc = filter("See #{link}...")
expect(doc.at_css('a').text).to eq link
doc = filter("See #{link}\"")
expect(doc.at_css('a').text).to eq link
doc = filter("See #{link}'")
expect(doc.at_css('a').text).to eq link
doc = filter("See #{link})")
expect(doc.at_css('a').text).to eq link
end
 
it 'does not include trailing HTML entities' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment