ignore whitespace inside markdown links
This commit is contained in:
parent
abedcc1cc3
commit
0847d09950
2 changed files with 8 additions and 8 deletions
|
|
@ -22,11 +22,11 @@ module MarkdownifyHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_links(message)
|
def process_links(message)
|
||||||
message.gsub!(/\[([^\[]+)\]\(([^ ]+) \"(([^&]|(&[^q])|(&q[^u])|(&qu[^o])|(&quo[^t])|("[^;]))+)\"\)/) do |m|
|
message.gsub!(/\[\s*([^\[]+)\s*\]\(\s*([^ ]+\s*) \"(([^&]|(&[^q])|(&q[^u])|(&qu[^o])|(&quo[^t])|("[^;]))+)\"\s*\)/) do |m|
|
||||||
escape = "\\"
|
escape = "\\"
|
||||||
link = $1
|
link = $1.strip
|
||||||
url = $2
|
url = $2.strip
|
||||||
title = $3
|
title = $3.strip
|
||||||
url.gsub!("_", "\\_")
|
url.gsub!("_", "\\_")
|
||||||
url.gsub!("*", "\\*")
|
url.gsub!("*", "\\*")
|
||||||
protocol = (url =~ /^\w+:\/\//) ? '' :'http://'
|
protocol = (url =~ /^\w+:\/\//) ? '' :'http://'
|
||||||
|
|
@ -34,10 +34,10 @@ module MarkdownifyHelper
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
message.gsub!(/\[([^\[]+)\]\(([^ ]+)\)/) do |m|
|
message.gsub!(/\[\s*([^\[]+)\s*\]\(\s*([^ ]+)\s*\)/) do |m|
|
||||||
escape = "\\"
|
escape = "\\"
|
||||||
link = $1
|
link = $1.strip
|
||||||
url = $2
|
url = $2.strip
|
||||||
url.gsub!("_", "\\_")
|
url.gsub!("_", "\\_")
|
||||||
url.gsub!("*", "\\*")
|
url.gsub!("*", "\\*")
|
||||||
protocol = (url =~ /^\w+:\/\//) ? '' :'http://'
|
protocol = (url =~ /^\w+:\/\//) ? '' :'http://'
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ describe MarkdownifyHelper do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have a robust link parsing" do
|
it "should have a robust link parsing" do
|
||||||
message = "This [*text*](http://en.wikipedia.org/wiki/Text_(literary_theory)) with many [links](google.com) tests [_http_](http://google.com/search?q=with_multiple__underscores*and**asterisks), [___FTP___](ftp://ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4 \"File Transfer Protocol\"), [**any protocol**](foo://bar.example.org/yes_it*makes*no_sense)"
|
message = "This [ *text* ]( http://en.wikipedia.org/wiki/Text_(literary_theory) ) with many [ links]( google.com) tests [_http_](http://google.com/search?q=with_multiple__underscores*and**asterisks ), [___FTP___]( ftp://ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4 \"File Transfer Protocol\"), [**any protocol**](foo://bar.example.org/yes_it*makes*no_sense)"
|
||||||
markdownify(message).should == 'This <a target="_blank" href="http://en.wikipedia.org/wiki/Text_(literary_theory)"><em>text</em></a> with many <a target="_blank" href="http://google.com">links</a> tests <a target="_blank" href="http://google.com/search?q=with_multiple__underscores*and**asterisks"><em>http</em></a>, <a target="_blank" href="ftp://ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4" title="File Transfer Protocol"><em><strong>FTP</strong></em></a>, <a target="_blank" href="foo://bar.example.org/yes_it*makes*no_sense"><strong>any protocol</strong></a>'
|
markdownify(message).should == 'This <a target="_blank" href="http://en.wikipedia.org/wiki/Text_(literary_theory)"><em>text</em></a> with many <a target="_blank" href="http://google.com">links</a> tests <a target="_blank" href="http://google.com/search?q=with_multiple__underscores*and**asterisks"><em>http</em></a>, <a target="_blank" href="ftp://ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4" title="File Transfer Protocol"><em><strong>FTP</strong></em></a>, <a target="_blank" href="foo://bar.example.org/yes_it*makes*no_sense"><strong>any protocol</strong></a>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue