Skip to content

Commit

Permalink
Merge pull request #6 from hugoabonizio/fix/markdown-compability
Browse files Browse the repository at this point in the history
Stdlib markdown compability
  • Loading branch information
hugoabonizio authored Aug 5, 2017
2 parents 6289eea + 34f96e7 commit 0a23c18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion spec/autolink_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "./spec_helper"
require "html"
require "markdown"

describe Autolink do
it "auto link URLs" do
Expand Down Expand Up @@ -77,7 +78,7 @@ describe Autolink do
auto_link("<p>#{url}</p>").should eq "<p>#{generate_result(url)}</p>"
end

it "already linked" do
it "ignores already linked" do
contents = [
"<a href=\"https://github.com\">https://github.com</a>",
"Welcome to my new blog at <a href=\"http://www.myblog.com/\" class=\"menu\" target=\"_blank\">http://www.myblog.com/</a>. Please e-mail me at <a href=\"mailto:[email protected]\" class=\"menu\" target=\"_blank\">[email protected]</a>.",
Expand All @@ -99,4 +100,18 @@ describe Autolink do
link = HTML.escape(%q(<a href="example">http://example.com</a>))
auto_link(link).should eq %q(&lt;a href&#61;&quot;example&quot;&gt;<a href="http://example.com">http://example.com</a>&lt;/a&gt;)
end

it "plays well with stdlib markdown" do
content = <<-EOF
auto_link("My blog: http://www.myblog.com")
My blog: <a href="http://www.myblog.com">http://www.myblog.com</a>
EOF

expected = <<-EOF
<p>auto_link("My blog: <a href="http://www.myblog.com">http://www.myblog.com</a>")
My blog: &lt;a href="http://www.myblog.com">http://www.myblog.com&lt;/a></p>
EOF

auto_link(Markdown.to_html(content)).should eq expected
end
end
2 changes: 1 addition & 1 deletion src/autolink.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Autolink
((.+?(?=&lt;)) | [^\s<\"]+)
}ix

AUTO_LINK_CRE = [/<[^>]+$/, /^[^>]*>/, /<a\b.*?>/i, /<\/a>/i]
AUTO_LINK_CRE = [/((<[^>]+$)|((&lt;[^>]+$)))/, /^[^>]*>/, /<a\b.*?>/i, /<\/a>/i]

BRACKETS = {"]" => "[", ")" => "(", "}" => "{"}

Expand Down

0 comments on commit 0a23c18

Please sign in to comment.