Ignores pre/code blocks

pull/454/head
Hagen Schink 11 years ago
parent 4e2227e5f9
commit 44fc4497e2
  1. 61
      db/migrate/migration_utils/text_references.rb

@ -94,14 +94,16 @@ module Migration
def update_work_package_macros(text, id_map, regex, macro_regex, new_macro) def update_work_package_macros(text, id_map, regex, macro_regex, new_macro)
unless text.nil? unless text.nil?
text.gsub!(regex) do |match| text = parse_non_pre_blocks(text) do |block|
if id_map.has_key? $~[:id].to_s block.gsub!(regex) do |match|
new_id = id_map[$~[:id].to_s][:new_id] if id_map.has_key? $~[:id].to_s
hash_macro = $~[:dots].gsub(macro_regex, new_macro) new_id = id_map[$~[:id].to_s][:new_id]
hash_macro = $~[:dots].gsub(macro_regex, new_macro)
" #{hash_macro}#{new_id} "
else " #{hash_macro}#{new_id} "
match else
match
end
end end
end end
end end
@ -111,8 +113,10 @@ module Migration
def update_issue_planning_element_links(text, id_map) def update_issue_planning_element_links(text, id_map)
unless text.nil? unless text.nil?
text.gsub!(work_package_link_regex) {|_| update_issue_planning_element_link_match $~, id_map} text = parse_non_pre_blocks(text) do |block|
text.gsub!(rel_work_package_link_regex) {|_| update_issue_planning_element_link_match $~, id_map} block.gsub!(work_package_link_regex) {|_| update_issue_planning_element_link_match $~, id_map}
block.gsub!(rel_work_package_link_regex) {|_| update_issue_planning_element_link_match $~, id_map}
end
end end
text text
@ -128,8 +132,10 @@ module Migration
def restore_issue_planning_element_links(text, id_map) def restore_issue_planning_element_links(text, id_map)
unless text.nil? unless text.nil?
text.gsub!(restore_work_package_link_regex) {|_| restore_issue_planning_element_link_match $~, id_map} text = parse_non_pre_blocks(text) do |block|
text.gsub!(restore_rel_work_package_link_regex) {|_| restore_issue_planning_element_link_match $~, id_map} text.gsub!(restore_work_package_link_regex) {|_| restore_issue_planning_element_link_match $~, id_map}
text.gsub!(restore_rel_work_package_link_regex) {|_| restore_issue_planning_element_link_match $~, id_map}
end
end end
text text
@ -166,6 +172,37 @@ module Migration
id id
end end
# taken from app/helper/application_helper.rb
def parse_non_pre_blocks(text)
s = StringScanner.new(text)
tags = []
parsed = ''
while !s.eos?
s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
if tags.empty?
yield text
end
parsed << text
if tag
if closing
if tags.last == tag.downcase
tags.pop
end
else
tags << tag.downcase
end
parsed << full_tag
end
end
# Close any non closing tags
while tag = tags.pop
parsed << "</#{tag}>"
end
parsed
end
def host_name def host_name
@host_name ||= select_host_name @host_name ||= select_host_name
end end

Loading…
Cancel
Save