imporvised smart_converter method to parsse content better

This commit is contained in:
Harry Bomrah 2016-03-07 18:34:23 +08:00
parent 8171fddea6
commit ad76febf40
1 changed files with 3 additions and 1 deletions

View File

@ -47,6 +47,8 @@ class AnnouncementFeedsController < ApplicationController
def smart_convertor(text) def smart_convertor(text)
html_string = text html_string = text
links = html_string.scan(/img.*?src="(.*?)"/i) links = html_string.scan(/img.*?src="(.*?)"/i)
links = links + html_string.scan(/a.*?href="(.*?)"/i)
links.uniq!
links.each do |link| links.each do |link|
l = link.first l = link.first
new_link = nil new_link = nil
@ -56,7 +58,7 @@ class AnnouncementFeedsController < ApplicationController
l1 = l.gsub("../","") l1 = l.gsub("../","")
new_link = request.protocol + request.host_with_port + "/" + l1 new_link = request.protocol + request.host_with_port + "/" + l1
end end
html_string = html_string.sub(l,new_link) if !new_link.nil? html_string = html_string.gsub(l,new_link) if !new_link.nil?
end end
return html_string return html_string
end end