From 0116c2c192ef926ef0a2876d3691648b6cffc43b Mon Sep 17 00:00:00 2001
From: izumiiii <41711526+izumiiii@users.noreply.github.com>
Date: Mon, 3 Jan 2022 15:05:02 +0900
Subject: [PATCH] refactor: fix_link_html
---
app/models/letter_opener_web/letter.rb | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/app/models/letter_opener_web/letter.rb b/app/models/letter_opener_web/letter.rb
index f662672..0f6ab13 100644
--- a/app/models/letter_opener_web/letter.rb
+++ b/app/models/letter_opener_web/letter.rb
@@ -126,15 +126,8 @@ def adjust_link_targets(contents)
end
def fix_link_html(link_html)
- # REFACTOR: we need a better way of fixing the link inner html
- link_html.dup.tap do |fixed_link|
- fixed_link.gsub!('
', '
')
- fixed_link.scan(/]+?)>/).each do |img|
- fixed_img = img.dup
- fixed_img.gsub!(/>$/, '/>') unless img =~ %r{/>$}
- fixed_link.gsub!(img, fixed_img)
- end
- end
+ link_html.gsub!('
', '
')
+ link_html.gsub(/]+?)>/) { |img| img =~ %r{/>$} ? img : img.gsub!(/>$/, '/>') }
end
end
end