处理从word粘贴图片不显示问题

This commit is contained in:
jacky 2024-05-09 18:26:58 +08:00
parent c766105374
commit 955a947411
1 changed files with 22 additions and 18 deletions

View File

@ -75,29 +75,33 @@ const handleCreated = (editor) => {
const customPaste = (editor, event, callback) => { const customPaste = (editor, event, callback) => {
let htmlData = event.clipboardData.getData('text/html') // html let htmlData = event.clipboardData.getData('text/html') // html
console.log(htmlData) // console.log(htmlData)
let rtfData = event.clipboardData.getData('text/rtf') // html let rtfData = event.clipboardData.getData('text/rtf') // html
console.log('-------------- rtfData --------------', rtfData) // console.log('-------------- rtfData --------------', rtfData)
htmlData = htmlData.replace(/<\/?span[^>]*>/g, ''); htmlData = htmlData.replace(/<\/?span[^>]*>/g, '');
htmlData = htmlData.replace('<img', '<img referrerpolicy="no-referrer"') htmlData = htmlData.replace(/<img/g, '<img referrerpolicy="no-referrer"')
// console.log('111111111111 replace after 1111111111', htmlData)
// word
// htmlimgsrc
const imgSrcs = htmlData.match(/<img [^>]*src=['"]([^'"]+)[^>]*>/g);
//
if (imgSrcs && Array.isArray(imgSrcs) && imgSrcs.length) {
console.log('imgSrcs', imgSrcs)
// rtf
const rtfImageData = extractImageDataFromRtf(rtfData);
console.log('rtfImageData', rtfImageData)
//
if (rtfImageData.length) {
// TODO,
// htmlimgsrcref if (rtfData !== "") {
htmlData = replaceImageFile(htmlData, imgSrcs, rtfImageData) // word
console.log('+++++++++++++++++++ replace after +++++++++++++++++++', htmlData) // htmlimgsrc
const imgSrcs = htmlData.match(/<img [^>]*src=['"]([^'"]+)[^>]*>/g);
//
if (imgSrcs && Array.isArray(imgSrcs) && imgSrcs.length) {
// console.log('imgSrcs', imgSrcs)
// rtf
const rtfImageData = extractImageDataFromRtf(rtfData);
// console.log('rtfImageData', rtfImageData)
//
if (rtfImageData.length) {
// TODO,
// htmlimgsrcref
htmlData = replaceImageFile(htmlData, imgSrcs, rtfImageData)
// console.log('22222222222222222 replace after 22222222222222222', htmlData)
}
} }
} }