From 40cc0ceae88b664261f4cb21c16ea8fde60e850b Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Wed, 1 Nov 2017 12:19:27 +0000 Subject: [PATCH 1/3] Add getConfig() function for SelectorManager --- src/selector_manager/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/selector_manager/index.js b/src/selector_manager/index.js index 815527a55..a05a92f5e 100644 --- a/src/selector_manager/index.js +++ b/src/selector_manager/index.js @@ -68,6 +68,15 @@ module.exports = config => { * @private */ name: 'SelectorManager', + + /** + * Get configuration object + * @return {Object} + * @private + */ + getConfig() { + return c; + }, /** * Initialize module. Automatically called with a new instance of the editor From 935ad309c3100a0fc15b3e6be47b99651548cf98 Mon Sep 17 00:00:00 2001 From: Tom Medema Date: Thu, 5 Apr 2018 10:52:31 -0700 Subject: [PATCH 2/3] implemented removeEmptyTextNodes boolean (defaults to true to prevent breaking changes); fixes #989 --- src/editor/config/config.js | 3 +++ src/editor/index.js | 1 + src/parser/model/ParserHtml.js | 9 ++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/editor/config/config.js b/src/editor/config/config.js index 09bd8f2b9..cdf4b7b32 100644 --- a/src/editor/config/config.js +++ b/src/editor/config/config.js @@ -62,6 +62,9 @@ module.exports = { // Ending tag for variable inside scripts in Components tagVarEnd: ' ]}', + // Remove empty text nodes when parsed, unless they contain a space + removeEmptyTextNodes: true, + // Return JS of components inside HTML from 'editor.getHtml()' jsInHtml: true, diff --git a/src/editor/index.js b/src/editor/index.js index 00ea2d4df..fa8db67f5 100644 --- a/src/editor/index.js +++ b/src/editor/index.js @@ -80,6 +80,7 @@ * @param {Object} [config.domComponents={}] Components configuration, see the relative documentation * @param {Object} [config.panels={}] Panels configuration, see the relative documentation * @param {Object} [config.showDevices=true] If true render a select of available devices inside style manager panel + * @param {Boolean} [config.removeEmptyTextNodes=true] If true, removes empty text nodes when parsed, unless they contain a space * @param {string} [config.defaultCommand='select-comp'] Command to execute when no other command is running * @param {Array} [config.plugins=[]] Array of plugins to execute on start * @param {Object} [config.pluginsOpts={}] Custom options for plugins diff --git a/src/parser/model/ParserHtml.js b/src/parser/model/ParserHtml.js index 021c5dbf9..0f56df1f5 100644 --- a/src/parser/model/ParserHtml.js +++ b/src/parser/model/ParserHtml.js @@ -57,6 +57,7 @@ module.exports = config => { * @return {Array} */ parseNode(el) { + const config = (c.em && c.em.get('Config')) || {}; const result = []; const nodes = el.childNodes; @@ -152,9 +153,11 @@ module.exports = config => { } // Throw away empty nodes (keep spaces) - const content = node.nodeValue; - if (content != ' ' && !content.trim()) { - continue; + if (config.removeEmptyTextNodes) { + const content = node.nodeValue; + if (content != ' ' && !content.trim()) { + continue; + } } } From 00d97955acbe9c4837aeb7bfa980df3cf34759c9 Mon Sep 17 00:00:00 2001 From: Tom Medema Date: Thu, 5 Apr 2018 11:33:33 -0700 Subject: [PATCH 3/3] negative strict equality check because config is not always available in test suite --- src/parser/model/ParserHtml.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/model/ParserHtml.js b/src/parser/model/ParserHtml.js index 0f56df1f5..c07ba3b4b 100644 --- a/src/parser/model/ParserHtml.js +++ b/src/parser/model/ParserHtml.js @@ -153,7 +153,7 @@ module.exports = config => { } // Throw away empty nodes (keep spaces) - if (config.removeEmptyTextNodes) { + if (config.removeEmptyTextNodes !== false) { const content = node.nodeValue; if (content != ' ' && !content.trim()) { continue;