lib/autolink.rb in twitter-text-1.4.9 vs lib/autolink.rb in twitter-text-1.4.10
- old
+ new
@@ -18,11 +18,11 @@
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,
:username_url_block, :list_url_block, :hashtag_url_block, :link_url_block,
- :suppress_lists, :suppress_no_follow]
+ :suppress_lists, :suppress_no_follow, :url_entities]
HTML_ENTITIES = {
'&' => '&',
'>' => '>',
'<' => '<',
@@ -137,18 +137,34 @@
# 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)
+
+ url_entities = {}
+ if options[:url_entities]
+ options[:url_entities].each do |entity|
+ entity = entity.with_indifferent_access
+ url_entities[entity[:url]] = entity
+ end
+ options.delete(:url_entities)
+ end
+
html_attrs = html_attrs_for_options(options)
Twitter::Rewriter.rewrite_urls(text) do |url|
href = if options[:link_url_block]
options.delete(:link_url_block).call(url)
else
html_escape(url)
end
- %(<a href="#{href}"#{html_attrs}>#{html_escape(url)}</a>)
+
+ display_url = url
+ if url_entities[url] && url_entities[url][:display_url]
+ display_url = url_entities[url][:display_url]
+ end
+
+ %(<a href="#{href}"#{html_attrs}>#{html_escape(display_url)}</a>)
end
end
private