Add ?, !, and : to trailing puncutation excluded from auto-linking
This commit is contained in:
parent
b06a44c4ea
commit
058dd19360
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Don't capture trailing punctuation when autolinking
|
||||||
|
merge_request: 17965
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -21,12 +21,13 @@ module Banzai
|
||||||
#
|
#
|
||||||
# See http://en.wikipedia.org/wiki/URI_scheme
|
# See http://en.wikipedia.org/wiki/URI_scheme
|
||||||
#
|
#
|
||||||
# The negative lookbehind ensures that users can paste a URL followed by a
|
# The negative lookbehind ensures that users can paste a URL followed by
|
||||||
# period or comma for punctuation without those characters being included
|
# punctuation without those characters being included in the generated
|
||||||
# in the generated link.
|
# link. It matches the behaviour of Rinku 2.0.1:
|
||||||
|
# https://github.com/vmg/rinku/blob/v2.0.1/ext/rinku/autolink.c#L65
|
||||||
#
|
#
|
||||||
# Rubular: http://rubular.com/r/JzPhi6DCZp
|
# Rubular: http://rubular.com/r/nrL3r9yUiq
|
||||||
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
|
# Text matching LINK_PATTERN inside these elements will not be linked
|
||||||
IGNORE_PARENTS = %w(a code kbd pre script style).to_set
|
IGNORE_PARENTS = %w(a code kbd pre script style).to_set
|
||||||
|
|
|
@ -122,14 +122,10 @@ describe Banzai::Filter::AutolinkFilter do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not include trailing punctuation' do
|
it 'does not include trailing punctuation' do
|
||||||
doc = filter("See #{link}.")
|
['.', ', ok?', '...', '?', '!', ': is that ok?'].each do |trailing_punctuation|
|
||||||
expect(doc.at_css('a').text).to eq link
|
doc = filter("See #{link}#{trailing_punctuation}")
|
||||||
|
expect(doc.at_css('a').text).to eq link
|
||||||
doc = filter("See #{link}, ok?")
|
end
|
||||||
expect(doc.at_css('a').text).to eq link
|
|
||||||
|
|
||||||
doc = filter("See #{link}...")
|
|
||||||
expect(doc.at_css('a').text).to eq link
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'includes trailing punctuation when part of a balanced pair' do
|
it 'includes trailing punctuation when part of a balanced pair' do
|
||||||
|
|
Loading…
Reference in New Issue