Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: fix_link_html #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions app/models/letter_opener_web/letter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!('<br>', '<br/>')
fixed_link.scan(/<img(?:[^>]+?)>/).each do |img|
fixed_img = img.dup
fixed_img.gsub!(/>$/, '/>') unless img =~ %r{/>$}
fixed_link.gsub!(img, fixed_img)
end
end
link_html.gsub!('<br>', '<br/>')
link_html.gsub(/<img(?:[^>]+?)>/) { |img| img =~ %r{/>$} ? img : img.gsub!(/>$/, '/>') }
end
end
end