Skip to content

Commit 5d76e28

Browse files
authored
Merge pull request #335 from mnishiguchi/mnishiguchi/autolink-configurability
Make AutolinkFilter configurable
2 parents 5209344 + 948df91 commit 5d76e28

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/html/pipeline/autolink_filter.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Pipeline
88
#
99
# Context options:
1010
# :autolink - boolean whether to autolink urls
11+
# :link_mode - :all, :urls or :email_addresses
1112
# :link_attr - HTML attributes for the link that will be generated
1213
# :skip_tags - HTML tags inside which autolinking will be skipped.
1314
# See Rinku.skip_tags
@@ -22,7 +23,11 @@ def call
2223
flags = 0
2324
flags |= context[:flags] if context[:flags]
2425

25-
Rinku.auto_link(html, :urls, context[:link_attr], skip_tags, flags)
26+
Rinku.auto_link(html, link_mode, context[:link_attr], skip_tags, flags)
27+
end
28+
29+
def link_mode
30+
context[:link_mode] || :urls
2631
end
2732
end
2833
end

test/html/pipeline/autolink_filter_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,24 @@ def test_autolink_skip_tags
3434
assert_equal '<code>"<a href="http://github.com">http://github.com</a>"</code>',
3535
AutolinkFilter.to_html('<code>"http://github.com"</code>', skip_tags: %w[kbd script])
3636
end
37+
38+
def test_link_mode_default
39+
assert_equal '<p>"<a href="http://www.github.com">http://www.github.com</a>"</p><p>"[email protected]"</p>',
40+
AutolinkFilter.to_html('<p>"http://www.github.com"</p><p>"[email protected]"</p>')
41+
end
42+
43+
def test_link_mode_urls
44+
assert_equal '<p>"<a href="http://www.github.com">http://www.github.com</a>"</p><p>"[email protected]"</p>',
45+
AutolinkFilter.to_html('<p>"http://www.github.com"</p><p>"[email protected]"</p>', link_mode: :urls)
46+
end
47+
48+
def test_link_mode_all
49+
assert_equal '<p>"<a href="http://www.github.com">http://www.github.com</a>"</p><p>"<a href="mailto:[email protected]">[email protected]</a>"</p>',
50+
AutolinkFilter.to_html('<p>"http://www.github.com"</p><p>"[email protected]"</p>', link_mode: :all)
51+
end
52+
53+
def test_link_mode_email_addresses
54+
assert_equal '<p>"http://www.github.com"</p><p>"<a href="mailto:[email protected]">[email protected]</a>"</p>',
55+
AutolinkFilter.to_html('<p>"http://www.github.com"</p><p>"[email protected]"</p>', link_mode: :email_addresses)
56+
end
3757
end

0 commit comments

Comments
 (0)