From 5a26533e797312ce898e7e334baf17ae34409497 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Wed, 29 Mar 2023 17:39:51 +0300 Subject: [PATCH] fix img id --- .../plugins/disallowPasteImagesPlugin.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js b/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js index bc562c059..42f1adfee 100644 --- a/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js +++ b/wax-prosemirror-services/src/ImageService/plugins/disallowPasteImagesPlugin.js @@ -1,4 +1,5 @@ /* eslint-disable no-param-reassign */ +import { v4 as uuidv4 } from 'uuid'; import { Plugin, PluginKey } from 'prosemirror-state'; const disallowPasteImagesPlugin = new PluginKey('disallowPasteImagesPlugin'); @@ -15,14 +16,23 @@ export default onWarning => { let imageFound = false; content.forEach(node => { if (node.type.name === 'image') { + node.attrs.id = uuidv4(); node.attrs.src = ''; node.attrs.alt = ''; imageFound = true; } if (node.type.name === 'figure') { - node.lastChild.attrs.src = ''; - node.lastChild.attrs.alt = ''; - imageFound = true; + if (node.firstChild && node.firstChild.type.name === 'image') { + node.firstChild.attrs.id = uuidv4(); + node.firstChild.attrs.src = ''; + node.firstChild.attrs.alt = ''; + imageFound = true; + } else if (node.lastChild && node.lastChild.type.name === 'image') { + node.lastChild.attrs.id = uuidv4(); + node.lastChild.attrs.src = ''; + node.lastChild.attrs.alt = ''; + imageFound = true; + } } }); if (imageFound) onWarning(); -- GitLab