From cdf0e96549989784e4e31162b73a3cddc8253262 Mon Sep 17 00:00:00 2001 From: Tdxdxoz Date: Thu, 9 Jul 2020 16:26:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86markdown=E5=A4=96?= =?UTF-8?q?=E9=93=BE=E5=9B=BE=E7=89=87=E7=9A=84=E6=98=BE=E7=A4=BA=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/formatter.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index aee209614..a3983df0f 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -277,15 +277,13 @@ class Formatter def link_to_url(entity, options = {}) url = Addressable::URI.parse(entity[:url]) - if entity[:img] - return img_html(entity[:url], entity[:link_text]) - end html_attrs = { target: '_blank', rel: 'nofollow noopener noreferrer' } html_attrs[:rel] = "me #{html_attrs[:rel]}" if options[:me] + html_attrs[:class] = "media-gallery__item-thumbnail" if entity[:img] - Twitter::Autolink.send(:link_to_text, entity, link_html(entity[:url], entity[:link_text]), url, html_attrs) + Twitter::Autolink.send(:link_to_text, entity, link_html(entity[:url], entity[:link_text], entity[:img]), url, html_attrs) rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError encode(entity[:url]) end @@ -312,15 +310,13 @@ class Formatter hashtag_html(entity[:hashtag]) end - def img_html(url, alt) - "\"#{alt}\"" - end - - def link_html(url, link_text) + def link_html(url, link_text, img) url = Addressable::URI.parse(url).to_s - - if link_text - return "#{link_text}" + + if img + return "\"#{link_text}\"" + elsif link_text + return "#{link_text}#{encode(url)}" end prefix = url.match(/\A(https?:\/\/(www\.)?|xmpp:)/).to_s