ignore whitespace inside markdown links

This commit is contained in:
MrZYX 2011-06-10 15:13:16 +02:00
parent abedcc1cc3
commit 0847d09950
2 changed files with 8 additions and 8 deletions

View file

@ -22,11 +22,11 @@ module MarkdownifyHelper
end
def process_links(message)
message.gsub!(/\[([^\[]+)\]\(([^ ]+) \"(([^&]|(&[^q])|(&q[^u])|(&qu[^o])|(&quo[^t])|(&quot[^;]))+)\"\)/) do |m|
message.gsub!(/\[\s*([^\[]+)\s*\]\(\s*([^ ]+\s*) \"(([^&]|(&[^q])|(&q[^u])|(&qu[^o])|(&quo[^t])|(&quot[^;]))+)\"\s*\)/) do |m|
escape = "\\"
link = $1
url = $2
title = $3
link = $1.strip
url = $2.strip
title = $3.strip
url.gsub!("_", "\\_")
url.gsub!("*", "\\*")
protocol = (url =~ /^\w+:\/\//) ? '' :'http://'
@ -34,10 +34,10 @@ module MarkdownifyHelper
res
end
message.gsub!(/\[([^\[]+)\]\(([^ ]+)\)/) do |m|
message.gsub!(/\[\s*([^\[]+)\s*\]\(\s*([^ ]+)\s*\)/) do |m|
escape = "\\"
link = $1
url = $2
link = $1.strip
url = $2.strip
url.gsub!("_", "\\_")
url.gsub!("*", "\\*")
protocol = (url =~ /^\w+:\/\//) ? '' :'http://'

View file

@ -214,7 +214,7 @@ describe MarkdownifyHelper do
end
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>'
end
end