diff --git a/packages/super-editor/src/editors/v1/core/DocxZipper.js b/packages/super-editor/src/editors/v1/core/DocxZipper.js index 7a5f752707..7a0081b1bf 100644 --- a/packages/super-editor/src/editors/v1/core/DocxZipper.js +++ b/packages/super-editor/src/editors/v1/core/DocxZipper.js @@ -11,7 +11,7 @@ import { reconcileDocumentRelationships, MANAGED_DOCUMENT_PARTS } from './opc/re const IMAGE_EXTS = new Set(['png', 'jpg', 'jpeg', 'gif', 'bmp', 'tiff', 'tif', 'emf', 'wmf', 'svg', 'webp']); /** Map file extensions to correct MIME sub-types where they differ. */ -const MIME_TYPE_FOR_EXT = { tif: 'tiff', jpg: 'jpeg' }; +const MIME_TYPE_FOR_EXT = { tif: 'tiff', jpg: 'jpeg', svg: 'svg+xml' }; const CUSTOM_XML_ITEM_PROPS_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.customXmlProperties+xml'; /** OOXML content types for embedded font file extensions. */ diff --git a/tests/behavior/tests/importing/fixtures/svg-image.docx b/tests/behavior/tests/importing/fixtures/svg-image.docx new file mode 100644 index 0000000000..a8c182acdf Binary files /dev/null and b/tests/behavior/tests/importing/fixtures/svg-image.docx differ diff --git a/tests/behavior/tests/importing/load-doc-with-svg.spec.ts b/tests/behavior/tests/importing/load-doc-with-svg.spec.ts new file mode 100644 index 0000000000..e9d8f22849 --- /dev/null +++ b/tests/behavior/tests/importing/load-doc-with-svg.spec.ts @@ -0,0 +1,32 @@ +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { test, expect } from '../../fixtures/superdoc.js'; +import { assertDocumentApiReady } from '../../helpers/document-api.js'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const DOC_PATH = path.resolve(__dirname, 'fixtures/svg-image.docx'); + +test.use({ config: { toolbar: 'full', comments: 'off' } }); + +test('loads DOCX with SVG image and renders it with the correct MIME type', async ({ superdoc }) => { + await superdoc.loadDocument(DOC_PATH); + await superdoc.waitForStable(); + await assertDocumentApiReady(superdoc.page); + + await expect(superdoc.page.locator('.superdoc-page').first()).toBeVisible(); + + const mediaEntry = await superdoc.page.evaluate(() => { + const editor = (window as any).editor; + const media = editor?.storage?.image?.media ?? {}; + const svgKey = Object.keys(media).find((k) => k.toLowerCase().endsWith('.svg')); + return svgKey ? { key: svgKey, value: media[svgKey] } : null; + }); + + expect(mediaEntry, 'imported SVG should be registered in editor.storage.image.media').not.toBeNull(); + expect(mediaEntry!.value, 'SVG data URI must use the image/svg+xml MIME type').toMatch( + /^data:image\/svg\+xml;base64,/, + ); + + const imgSrc = await superdoc.page.locator('img').first().getAttribute('src'); + expect(imgSrc, 'rendered should resolve to the SVG data URI').toMatch(/^data:image\/svg\+xml;base64,/); +});