mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-22 06:44:55 +08:00
Merge pull request #1736 from aignatov-bio/ai-sci-3423-add-old-tinymce-support
Add old tinymce image support [SCI-3423]
This commit is contained in:
commit
bbf54de9c7
2 changed files with 16 additions and 2 deletions
|
@ -13,6 +13,10 @@ module TinyMceImages
|
|||
|
||||
def prepare_for_report(field)
|
||||
description = self[field]
|
||||
|
||||
# Check tinymce for old format
|
||||
description = TinyMceAsset.update_old_tinymce(description)
|
||||
|
||||
tiny_mce_assets.each do |tm_asset|
|
||||
tmp_f = Tempfile.open(tm_asset.image_file_name, Rails.root.join('tmp'))
|
||||
begin
|
||||
|
@ -41,7 +45,12 @@ module TinyMceImages
|
|||
# and updates references in assosiated object's description
|
||||
def reassign_tiny_mce_image_references(images = [])
|
||||
object_field = Extends::RICH_TEXT_FIELD_MAPPINGS[self.class.name]
|
||||
parsed_description = Nokogiri::HTML(read_attribute(object_field))
|
||||
description = read_attribute(object_field)
|
||||
|
||||
# Check tinymce for old format
|
||||
description = TinyMceAsset.update_old_tinymce(description)
|
||||
|
||||
parsed_description = Nokogiri::HTML(description)
|
||||
images.each do |image|
|
||||
old_id = image[0]
|
||||
new_id = image[1]
|
||||
|
|
|
@ -49,6 +49,9 @@ class TinyMceAsset < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.generate_url(description)
|
||||
# Check tinymce for old format
|
||||
description = update_old_tinymce(description)
|
||||
|
||||
description = Nokogiri::HTML(description)
|
||||
tm_assets = description.css('img')
|
||||
tm_assets.each do |tm_asset|
|
||||
|
@ -103,9 +106,11 @@ class TinyMceAsset < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.update_old_tinymce(description)
|
||||
return description unless description
|
||||
|
||||
description.scan(/\[~tiny_mce_id:(\w+)\]/).flatten.each do |token|
|
||||
old_format = /\[~tiny_mce_id:#{token}\]/
|
||||
new_format = "<img src=\"\" class=\"img-responsive\" data-mce-token=\"#{Base62.encode(token)}\"/>"
|
||||
new_format = "<img src=\"\" class=\"img-responsive\" data-mce-token=\"#{Base62.encode(token.to_i)}\"/>"
|
||||
description.sub!(old_format, new_format)
|
||||
end
|
||||
description
|
||||
|
|
Loading…
Reference in a new issue