diff --git a/www/diagram/export.js b/www/diagram/export.js index 79f9c7be7..09e5da30b 100644 --- a/www/diagram/export.js +++ b/www/diagram/export.js @@ -3,15 +3,10 @@ // SPDX-License-Identifier: AGPL-3.0-or-later define([ - '/components/x2js/x2js.js', '/diagram/util.js', ], function ( - X2JS, DiagramUtil ) { - const x2js = new X2JS(); - const jsonContentAsXML = (content) => x2js.js2xml(content); - const parseDrawioStyle = (styleAttrValue) => { if (!styleAttrValue) { return; @@ -70,12 +65,12 @@ define([ } return doc; }; - + return { main: function(userDoc, cb) { delete userDoc.metadata; - const xml = jsonContentAsXML(userDoc); + const xml = DiagramUtil.jsonContentAsXML(userDoc); let doc; try { diff --git a/www/diagram/inner.js b/www/diagram/inner.js index 5030bf491..b6176c1cf 100644 --- a/www/diagram/inner.js +++ b/www/diagram/inner.js @@ -95,11 +95,9 @@ define([ drawioFrame.contentWindow.postMessage(JSON.stringify(msg), '*'); }; - const jsonContentAsXML = (content) => x2js.js2xml(content); - var onDrawioInit = function() { drawIoInitalized = true; - var xmlStr = jsonContentAsXML(lastContent); + var xmlStr = DiagramUtil.jsonContentAsXML(lastContent); postMessageToDrawio({ action: 'load', xml: xmlStr, @@ -165,7 +163,7 @@ define([ // This is the function from which you will receive updates from CryptPad framework.onContentUpdate(function (newContent) { lastContent = newContent; - var xmlStr = jsonContentAsXML(lastContent); + var xmlStr = DiagramUtil.jsonContentAsXML(lastContent); postMessageToDrawio({ action: 'merge', xml: xmlStr, diff --git a/www/diagram/util.js b/www/diagram/util.js index c56562236..72acda93a 100644 --- a/www/diagram/util.js +++ b/www/diagram/util.js @@ -6,12 +6,15 @@ define([ '/common/common-util.js', '/file/file-crypto.js', '/common/outer/cache-store.js', + '/components/x2js/x2js.js', ], function ( Util, FileCrypto, - Cache + Cache, + X2JS, ) { const Nacl = window.nacl; + const x2js = new X2JS(); const parseCryptPadUrl = function(href) { const url = new URL(href); @@ -38,9 +41,18 @@ define([ return fixedBlob; }; + const jsonContentAsXML = (content) => { + + // Sometimes `content` has additional fiels, that break the XML output. Only grab mxfile here. + const cleaned = { mxfile: content.mxfile }; + + return x2js.js2xml(cleaned); + }; + return { parseCryptPadUrl, getCryptPadUrl, + jsonContentAsXML, loadImage: function(href) { return new Promise((resolve, reject) => {