From 1803cbc8aa9fb33403aa36dffe52126cc8850a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=BF=97=E5=9D=9A?= Date: Thu, 4 Aug 2022 16:18:05 +0800 Subject: [PATCH] fill miss node with '' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit using empty string to make jsonMap completed. There is a scenario。 copy from xmind ` node1 node2 node3 node3-1 node4 ` actually, node3 is node3\n node3-1 。but when i copy the xmind node , will get above text. then it cannot be imported . so i fill empty string so that make sure it can be imported ,which increasing user friendly --- src/core/data.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/data.js b/src/core/data.js index a851000f..13100b77 100644 --- a/src/core/data.js +++ b/src/core/data.js @@ -142,7 +142,17 @@ define(function(require, exports, module) { importChildren(childNode, children[i].children); } } - + function fillEmptyNode(jsonMap, level) { + if (jsonMap[level]){ + return; + } + jsonMap[level] = {"children":[], "data":{"text":""}}; + if (level < 1) { + return; + } + fillEmptyNode(jsonMap, level - 1); + addChild(jsonMap[level - 1], jsonMap[level]) + } while ((line = lines[i++]) !== undefined) { line = line.replace(/ /g, ''); if (isEmpty(line)) continue; @@ -155,7 +165,7 @@ define(function(require, exports, module) { jsonMap[0] = children[children.length-1]; } else { if (!jsonMap[level-1]) { - throw new Error('Invalid local format'); + fillEmptyNode(jsonMap, level -1); }; addChild(jsonMap[level-1], jsonNode); jsonMap[level] = jsonNode; @@ -359,4 +369,4 @@ define(function(require, exports, module) { return Promise.resolve(protocol.decode(data, this, option)) } }); -}); \ No newline at end of file +});