lib/autolink.rb in twitter-text-1.4.1 vs lib/autolink.rb in twitter-text-1.4.2
- old
+ new
@@ -14,10 +14,14 @@
DEFAULT_HASHTAG_CLASS = "hashtag"
# Default target for auto-linked urls (nil will not add a target attribute)
DEFAULT_TARGET = nil
# HTML attribute for robot nofollow behavior (default)
HTML_ATTR_NO_FOLLOW = " rel=\"nofollow\""
+ # Options which should not be passed as HTML attributes
+ OPTIONS_NOT_ATTRIBUTES = [:url_class, :list_class, :username_class, :hashtag_class,
+ :username_url_base, :list_url_base, :hashtag_url_base,
+ :suppress_lists, :suppress_no_follow]
HTML_ENTITIES = {
'&' => '&',
'>' => '>',
'<' => '<',
@@ -99,11 +103,11 @@
"#{before}#{at}#{user}#{slash_listname}"
else
# this is a screen name
chunk = user
chunk = yield(chunk) if block_given?
- "#{before}#{at}<a class=\"#{options[:url_class]} #{options[:username_class]}\" #{target_tag(options)}href=\"#{html_escape(options[:username_url_base])}#{html_escape(chunk)}\"#{extra_html}>#{html_escape(chunk)}</a>"
+ "#{before}#{at}<a class=\"#{options[:url_class]} #{options[:username_class]}\" #{target_tag(options)}href=\"#{html_escape(options[:username_url_base])}#{html_escape(chunk)}\"#{extra_html}>#{html_escape(chunk)}</a>#{slash_listname}"
end
end
end
end
end
@@ -141,14 +145,15 @@
# and place in the <tt><a></tt> tag. Unless <tt>href_options</tt> contains <tt>:suppress_no_follow</tt>
# the <tt>rel="nofollow"</tt> attribute will be added.
def auto_link_urls_custom(text, href_options = {})
options = href_options.dup
options[:rel] = "nofollow" unless options.delete(:suppress_no_follow)
+ options[:class] = options.delete(:url_class)
text.gsub(Twitter::Regex[:valid_url]) do
all, before, url, protocol, domain, path, query_string = $1, $2, $3, $4, $5, $6, $7
if !protocol.blank?
- html_attrs = tag_options(options.stringify_keys) || ""
+ html_attrs = tag_options(options.reject{|k,v| OPTIONS_NOT_ATTRIBUTES.include?(k) }.stringify_keys) || ""
"#{before}<a href=\"#{html_escape(url)}\"#{html_attrs}>#{html_escape(url)}</a>"
else
all
end
end