module Fiona7 module LinkConverter class ScrivitoToFiona def initialize(klass, value) @klass, @value = klass, value.to_str end def convert serialize_html end private def serialize_html # TODO: this an incomplete list of possible tags if Fiona7.mode == :legacy link_expressions = [/(src|href)\s*=\s*"([^"]*)"/, /(src|href)\s*=\s*'([^']*)'/] else # in standalone mode image links cannot be stored correctly link_expressions = [/(href)\s*=\s*"([^"]*)"/, /(href)\s*=\s*'([^']*)'/] end link_expressions.each do |expr| @value.gsub!(expr) do |string| target = $2 objid = objid_from_target(target) if objid "#{$1}=\"#{obj_path(objid)}\"" else string end end end @value end def objid_from_target(target) if (match = target.match(/\Aobjid:([0-9a-f]+)\Z/)) match[1] end end def obj_path(id) @klass.find(id).try(:path) end end end end