diff --git a/spec/autolink_spec.cr b/spec/autolink_spec.cr index 5f97191..f9714a3 100644 --- a/spec/autolink_spec.cr +++ b/spec/autolink_spec.cr @@ -1,5 +1,6 @@ require "./spec_helper" require "html" +require "markdown" describe Autolink do it "auto link URLs" do @@ -77,7 +78,7 @@ describe Autolink do auto_link("

#{url}

").should eq "

#{generate_result(url)}

" end - it "already linked" do + it "ignores already linked" do contents = [ "https://github.com", "Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.", @@ -99,4 +100,18 @@ describe Autolink do link = HTML.escape(%q(http://example.com)) auto_link(link).should eq %q(<a href="example">http://example.com</a>) end + + it "plays well with stdlib markdown" do + content = <<-EOF + auto_link("My blog: http://www.myblog.com") + My blog: http://www.myblog.com + EOF + + expected = <<-EOF +

auto_link("My blog: http://www.myblog.com") + My blog: <a href="http://www.myblog.com">http://www.myblog.com</a>

+ EOF + + auto_link(Markdown.to_html(content)).should eq expected + end end diff --git a/src/autolink.cr b/src/autolink.cr index 31d58f3..6a5bb9f 100644 --- a/src/autolink.cr +++ b/src/autolink.cr @@ -6,7 +6,7 @@ module Autolink ((.+?(?=<)) | [^\s<\"]+) }ix - AUTO_LINK_CRE = [/<[^>]+$/, /^[^>]*>/, //i, /<\/a>/i] + AUTO_LINK_CRE = [/((<[^>]+$)|((<[^>]+$)))/, /^[^>]*>/, //i, /<\/a>/i] BRACKETS = {"]" => "[", ")" => "(", "}" => "{"}