fixes #2095
This commit is contained in:
@@ -58,19 +58,24 @@ class DText
|
||||
end
|
||||
|
||||
def self.parse_links(str)
|
||||
str.gsub(/("[^"]+":(https?:\/\/|\/)[^\s\r\n<>]+|https?:\/\/[^\s\r\n<>]+)+/) do |url|
|
||||
if url =~ /^"([^"]+)":(.+)$/
|
||||
str.gsub(/("[^"]+":(https?:\/\/|\/)[^\s\r\n<>]+|https?:\/\/[^\s\r\n<>]+|"[^"]+":\[(https?:\/\/|\/)[^\s\r\n<>\]]+\])+/) do |url|
|
||||
ch = ""
|
||||
|
||||
if url =~ /^"([^"]+)":\[(.+)\]$/
|
||||
text = $1
|
||||
url = $2
|
||||
else
|
||||
text = url
|
||||
end
|
||||
if url =~ /^"([^"]+)":(.+)$/
|
||||
text = $1
|
||||
url = $2
|
||||
else
|
||||
text = url
|
||||
end
|
||||
|
||||
if url =~ /([;,.!?\)\]<>])$/
|
||||
url.chop!
|
||||
ch = $1
|
||||
else
|
||||
ch = ""
|
||||
if url =~ /([;,.!?\)\]<>])$/
|
||||
url.chop!
|
||||
ch = $1
|
||||
end
|
||||
end
|
||||
|
||||
'<a href="' + url + '">' + text + '</a>' + ch
|
||||
|
||||
@@ -105,7 +105,7 @@ class DTextTest < ActiveSupport::TestCase
|
||||
assert_equal('<p>a (<a href="http://test.com">http://test.com</a>) b</p>', p('a (http://test.com) b'))
|
||||
end
|
||||
|
||||
def test_old_syle_links
|
||||
def test_old_style_links
|
||||
assert_equal('<p><a href="http://test.com">test</a></p>', p('"test":http://test.com'))
|
||||
end
|
||||
|
||||
@@ -113,6 +113,16 @@ class DTextTest < ActiveSupport::TestCase
|
||||
assert_equal('<p>"1" <a href="http://three.com">2 & 3</a></p>', p('"1" "2 & 3":http://three.com'))
|
||||
end
|
||||
|
||||
def test_new_style_links
|
||||
assert_equal('<p><a href="http://test.com">test</a></p>', p('"test":[http://test.com]'))
|
||||
end
|
||||
|
||||
def test_new_style_links_with_parentheses
|
||||
assert_equal('<p><a href="http://test.com/(parentheses)">test</a></p>', p('"test":[http://test.com/(parentheses)]'))
|
||||
assert_equal('<p>(<a href="http://test.com/(parentheses)">test</a>)</p>', p('("test":[http://test.com/(parentheses)])'))
|
||||
assert_equal('<p>[<a href="http://test.com/(parentheses)">test</a>]</p>', p('["test":[http://test.com/(parentheses)]]'))
|
||||
end
|
||||
|
||||
def test_lists_1
|
||||
assert_equal('<ul><li>a</li></ul>', p('* a'))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user