link_url_with_entity

in rb/lib/twitter-text/autolink.rb [278:336]


      def link_url_with_entity(entity, options)
        display_url = entity[:display_url]
        expanded_url = entity[:expanded_url]
        invisible_tag_attrs = options[:invisible_tag_attrs] || DEFAULT_INVISIBLE_TAG_ATTRS

        # Goal: If a user copies and pastes a tweet containing t.co'ed link, the resulting paste
        # should contain the full original URL (expanded_url), not the display URL.
        #
        # Method: Whenever possible, we actually emit HTML that contains expanded_url, and use
        # font-size:0 to hide those parts that should not be displayed (because they are not part of display_url).
        # Elements with font-size:0 get copied even though they are not visible.
        # Note that display:none doesn't work here. Elements with display:none don't get copied.
        #
        # Additionally, we want to *display* ellipses, but we don't want them copied.  To make this happen we
        # wrap the ellipses in a tco-ellipsis class and provide an onCopy handler that sets display:none on
        # everything with the tco-ellipsis class.
        #
        # Exception: pic.twitter.com images, for which expandedUrl = "https://twitter.com/username/status/1234/photo/1
        
        
        display_url_sans_ellipses = display_url.gsub("…", "")

        if expanded_url.include?(display_url_sans_ellipses)
          before_display_url, after_display_url = expanded_url.split(display_url_sans_ellipses, 2)
          preceding_ellipsis = /\A…/.match(display_url).to_s
          following_ellipsis = /…\z/.match(display_url).to_s

          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          %(<span class="tco-ellipsis">
            %(<span 
            %(<span class="js-display-url">
            %(<span 
            %(<span class="tco-ellipsis"><span 
        else
          html_escape(display_url)
        end
      end