Skip to content

Commit 73b9982

Browse files
committed
Merge pull request #65 from pengwynn/autolink-skip-tags
Allow passing skip_tags in autolink filter context
2 parents 60b8b85 + d77e92f commit 73b9982

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/html/pipeline/autolink_filter.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ class Pipeline
55
# HTML Filter for auto_linking urls in HTML.
66
#
77
# Context options:
8-
# :autolink - boolean whether to autolink urls
9-
# :flags - additional Rinku flags. See https://github.com/vmg/rinku
8+
# :autolink - boolean whether to autolink urls
9+
# :skip_tags - HTML tags inside which autolinking will be skipped.
10+
# See Rinku.skip_tags
11+
# :flags - additional Rinku flags. See https://github.com/vmg/rinku
1012
#
1113
# This filter does not write additional information to the context.
1214
class AutolinkFilter < Filter
1315
def call
1416
return html if context[:autolink] == false
17+
18+
skip_tags = context[:skip_tags]
1519
flags = 0
1620
flags |= context[:flags] if context[:flags]
1721

18-
Rinku.auto_link(html, :urls, nil, %w[a script kbd pre code], flags)
22+
Rinku.auto_link(html, :urls, nil, skip_tags, flags)
1923
end
2024
end
2125
end
22-
end
26+
end

test/html/pipeline/autolink_filter_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ def test_autolink_flags
1919
assert_equal '<p>"<a href="http://github">http://github</a>"</p>',
2020
AutolinkFilter.to_html('<p>"http://github"</p>', :flags => Rinku::AUTOLINK_SHORT_DOMAINS)
2121
end
22+
23+
def test_autolink_skip_tags
24+
assert_equal '<code>"http://github.com"</code>',
25+
AutolinkFilter.to_html('<code>"http://github.com"</code>')
26+
27+
assert_equal '<code>"<a href="http://github.com">http://github.com</a>"</code>',
28+
AutolinkFilter.to_html('<code>"http://github.com"</code>', :skip_tags => %w(kbd script))
29+
end
2230
end

0 commit comments

Comments
 (0)