Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing skip_tags in autolink filter context #65

Merged
merged 1 commit into from
Jul 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/html/pipeline/autolink_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ class Pipeline
# HTML Filter for auto_linking urls in HTML.
#
# Context options:
# :autolink - boolean whether to autolink urls
# :flags - additional Rinku flags. See https://github.com/vmg/rinku
# :autolink - boolean whether to autolink urls
# :skip_tags - HTML tags inside which autolinking will be skipped.
# See Rinku.skip_tags
# :flags - additional Rinku flags. See https://github.com/vmg/rinku
#
# This filter does not write additional information to the context.
class AutolinkFilter < Filter
def call
return html if context[:autolink] == false

skip_tags = context[:skip_tags]
flags = 0
flags |= context[:flags] if context[:flags]

Rinku.auto_link(html, :urls, nil, %w[a script kbd pre code], flags)
Rinku.auto_link(html, :urls, nil, skip_tags, flags)
end
end
end
end
end
8 changes: 8 additions & 0 deletions test/html/pipeline/autolink_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ def test_autolink_flags
assert_equal '<p>"<a href="http://github">http://github</a>"</p>',
AutolinkFilter.to_html('<p>"http://github"</p>', :flags => Rinku::AUTOLINK_SHORT_DOMAINS)
end

def test_autolink_skip_tags
assert_equal '<code>"http://github.com"</code>',
AutolinkFilter.to_html('<code>"http://github.com"</code>')

assert_equal '<code>"<a href="http://github.com">http://github.com</a>"</code>',
AutolinkFilter.to_html('<code>"http://github.com"</code>', :skip_tags => %w(kbd script))
end
end