Skip to content

Commit

Permalink
implemented removeEmptyTextNodes boolean (defaults to true to prevent…
Browse files Browse the repository at this point in the history
… breaking changes); fixes GrapesJS#989
  • Loading branch information
tommedema committed Apr 5, 2018
1 parent 376a608 commit 935ad30
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/editor/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
1 change: 1 addition & 0 deletions src/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/parser/model/ParserHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = config => {
* @return {Array<Object>}
*/
parseNode(el) {
const config = (c.em && c.em.get('Config')) || {};
const result = [];
const nodes = el.childNodes;

Expand Down Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 935ad30

Please sign in to comment.