mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-08 07:21:03 +08:00
Fix import for eln (#1741)
This commit is contained in:
parent
364f903b3c
commit
3633274c8f
2 changed files with 16 additions and 13 deletions
|
|
@ -293,17 +293,16 @@ function importProtocolFromFile(
|
|||
stepGuid,
|
||||
element.getAttribute('fileref'));
|
||||
|
||||
if (description.includes('[~tiny_mce_id')) {
|
||||
// old format load
|
||||
imageTag = '<img style="max-width:300px; max-height:300px;" src="data:' + element.children[1].innerHTML + ';base64,' + assetBytes + '" />';
|
||||
description = description.replace(match, imageTag);
|
||||
} else {
|
||||
// new format load
|
||||
description = $('<div>' + description + '</div>').find('img[data-mce-token="' + element.getAttribute('tokenId') + '"]')
|
||||
.attr('src', 'data:' + element.children[1].innerHTML + ';base64,' + assetBytes).prop('outerHTML');
|
||||
}
|
||||
});
|
||||
// new format load
|
||||
description = $('<div>' + description + '</div>');
|
||||
description.find('img[data-mce-token="' + element.getAttribute('tokenId') + '"]')
|
||||
.attr('src', 'data:' + element.children[1].innerHTML + ';base64,' + assetBytes);
|
||||
description = description.prop('outerHTML');
|
||||
|
||||
// old format load
|
||||
imageTag = '<img style="max-width:300px; max-height:300px;" src="data:' + element.children[1].innerHTML + ';base64,' + assetBytes + '" />';
|
||||
description = description.replace(match, imageTag);
|
||||
});
|
||||
// I know is crazy but is the only way I found to pass valid HTML
|
||||
return $('<div></div>').html(description).html();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,10 +158,14 @@ module ProtocolsImporter
|
|||
)
|
||||
tiny_mce_img.image_content_type = tiny_mce_img_json['fileType']
|
||||
tiny_mce_img.save!
|
||||
if description.gsub!("data-mce-token=\"#{tiny_mce_img_json['tokenId']}\"",
|
||||
"data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"")
|
||||
description.gsub!(' ]]-->', '')
|
||||
|
||||
description.gsub!("data-mce-token=\"#{tiny_mce_img_json['tokenId']}\"",
|
||||
"data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"")
|
||||
.gsub!(' ]]-->', '')
|
||||
else
|
||||
description.gsub!("data-mce-token=\"#{Base62.encode(tiny_mce_img_json['tokenId'].to_i)}\"",
|
||||
"data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"").gsub!(' ]]-->', '')
|
||||
end
|
||||
end
|
||||
description
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue