require 'nokogiri' module Scrivito class ContentConversion def self.convert_html_links(input, request_host, request_port) doc = Nokogiri::HTML.parse("
#{input}
") doc.css('body a').each do |a_tag| if href = a_tag.attributes['href'] link = Link.parse(href.value, request_host, request_port) href.value = link.to_cms_api_html_url end end doc.css('body img').each do |img_tag| if src = img_tag.attributes['src'] link = Link.parse(src.value, request_host, request_port) src.value = link.to_cms_api_html_url end end new_html = doc.css('body div.internal_jump_point').inner_html nbsp = Nokogiri::HTML(" ").text new_html.gsub(nbsp, " ") end def self.convert_linklist_urls(linklist, request_host, request_port) linklist.map do |link_data| convert_link(link_data, request_host, request_port) end end def self.convert_link(link_data, request_host, request_port) return unless link_data if url = link_data.delete(:url) link_data.delete(:obj_id) link = Link.parse(url, request_host, request_port) link_data.merge!(link.to_cms_api_linklist_params) end if obj_id = link_data.delete(:obj_id) link_data.merge!(obj: Obj.find(obj_id)) end Link.new(link_data) end end end