From 50a679c0302fa727e5394052cd700e1f5bee44ba Mon Sep 17 00:00:00 2001 From: Hugo Abonizio Date: Fri, 4 Aug 2017 17:43:57 -0300 Subject: [PATCH 1/2] fix: Leave tags coming from stdlib markdown as is --- spec/autolink_spec.cr | 15 ++++++++++++++- src/autolink.cr | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/autolink_spec.cr b/spec/autolink_spec.cr index 5f97191..ed53d97 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,16 @@ 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 = {"]" => "[", ")" => "(", "}" => "{"} From 34f96e76df3a86d698c3ecf76f7f0f9f35dfcfb9 Mon Sep 17 00:00:00 2001 From: Vitalii Elenhaupt Date: Sat, 5 Aug 2017 00:03:33 +0300 Subject: [PATCH 2/2] Make it a bit more readable --- spec/autolink_spec.cr | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/autolink_spec.cr b/spec/autolink_spec.cr index ed53d97..f9714a3 100644 --- a/spec/autolink_spec.cr +++ b/spec/autolink_spec.cr @@ -103,13 +103,15 @@ describe Autolink do it "plays well with stdlib markdown" do content = <<-EOF -auto_link("My blog: http://www.myblog.com") -My blog: http://www.myblog.com -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("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