diff --git a/packages/super-editor/src/core/DocxZipper.js b/packages/super-editor/src/core/DocxZipper.js index 9c5a03aff..4ba50a94c 100644 --- a/packages/super-editor/src/core/DocxZipper.js +++ b/packages/super-editor/src/core/DocxZipper.js @@ -48,12 +48,15 @@ class DocxZipper { name: zipEntry.name, content, }); - } else if (zipEntry.name.startsWith('word/media') && zipEntry.name !== 'word/media/') { + } else if ( + (zipEntry.name.startsWith('word/media') && zipEntry.name !== 'word/media/') || + (zipEntry.name.startsWith('media') && zipEntry.name !== 'media/') + ) { // If we are in node, we need to convert the buffer to base64 if (isNode) { const buffer = await zipEntry.async('nodebuffer'); const fileBase64 = buffer.toString('base64'); - mediaObjects[zipEntry.name] = fileBase64; + this.mediaFiles[zipEntry.name] = fileBase64; } // If we are in the browser, we can use the base64 directly @@ -215,9 +218,9 @@ class DocxZipper { zip.file(key, content); }); - Object.keys(media).forEach((name) => { - const binaryData = Buffer.from(media[name], 'base64'); - zip.file(`word/media/${name}`, binaryData); + Object.keys(media).forEach((path) => { + const binaryData = Buffer.from(media[path], 'base64'); + zip.file(path, binaryData); }); // Export font files @@ -252,8 +255,8 @@ class DocxZipper { unzippedOriginalDocx.file(key, updatedDocs[key]); }); - Object.keys(media).forEach((name) => { - unzippedOriginalDocx.file(`word/media/${name}`, media[name]); + Object.keys(media).forEach((path) => { + unzippedOriginalDocx.file(path, media[path]); }); await this.updateContentTypes(unzippedOriginalDocx, media); diff --git a/packages/super-editor/src/core/super-converter/SuperConverter.js b/packages/super-editor/src/core/super-converter/SuperConverter.js index 902d3e4a5..6a1b5562b 100644 --- a/packages/super-editor/src/core/super-converter/SuperConverter.js +++ b/packages/super-editor/src/core/super-converter/SuperConverter.js @@ -712,8 +712,7 @@ class SuperConverter { const processedData = {}; for (const filePath in media) { if (typeof media[filePath] !== 'string') continue; - const name = filePath.split('/').pop(); - processedData[name] = await getArrayBufferFromUrl(media[filePath], editor.options.isHeadless); + processedData[filePath] = await getArrayBufferFromUrl(media[filePath], editor.options.isHeadless); } this.convertedXml.media = { diff --git a/packages/super-editor/src/core/super-converter/exporter.js b/packages/super-editor/src/core/super-converter/exporter.js index 8a235ae46..5e59ad6f4 100644 --- a/packages/super-editor/src/core/super-converter/exporter.js +++ b/packages/super-editor/src/core/super-converter/exporter.js @@ -1556,7 +1556,7 @@ function translateImageNode(params, imageSize) { const src = attrs.src || attrs.imageSrc; const { originalWidth, originalHeight } = getPngDimensions(src); - const imageName = params.node.type === 'image' ? src?.split('word/media/')[1] : attrs.fieldId?.replace('-', '_'); + const imageName = params.node.type === 'image' ? src.split('/').pop() : attrs.fieldId?.replace('-', '_'); let size = attrs.size ? { diff --git a/packages/super-editor/src/core/super-converter/v2/importer/imageImporter.js b/packages/super-editor/src/core/super-converter/v2/importer/imageImporter.js index 4220bbf6b..e9b8814c4 100644 --- a/packages/super-editor/src/core/super-converter/v2/importer/imageImporter.js +++ b/packages/super-editor/src/core/super-converter/v2/importer/imageImporter.js @@ -116,8 +116,12 @@ export function handleImageImport(node, currentFileName, params) { if (!rel) return null; const { attributes: relAttributes } = rel; + const targetPath = relAttributes['Target']; - const path = `word/${relAttributes['Target']}`; + let path = `word/${targetPath}`; + + // Some images may appear out of the word folder + if (targetPath.startsWith('/word') || targetPath.startsWith('/media')) path = targetPath.substring(1); return { type: 'image', diff --git a/packages/super-editor/src/dev/components/DeveloperPlayground.vue b/packages/super-editor/src/dev/components/DeveloperPlayground.vue index ef11f2f58..2baa99b60 100644 --- a/packages/super-editor/src/dev/components/DeveloperPlayground.vue +++ b/packages/super-editor/src/dev/components/DeveloperPlayground.vue @@ -3,6 +3,7 @@ import '@/style.css'; import '@harbour-enterprises/common/styles/common-styles.css'; import { ref, shallowRef, computed, onMounted } from 'vue'; +import { NMessageProvider } from 'naive-ui'; import { SuperEditor } from '@/index.js'; import { getFileObject } from '@harbour-enterprises/common/helpers/get-file-object'; import { DOCX } from '@harbour-enterprises/common'; @@ -158,7 +159,9 @@ onMounted(async () => {