Skip to content

Commit

Permalink
Filter out empty nodes from tinymce
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee committed Apr 14, 2021
1 parent a28ae57 commit b0496e8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions static/js/com/rich-editor.js
Expand Up @@ -240,6 +240,9 @@ export class RichEditor extends LitElement {
editor.setContent(this.initialValue, {format: 'html'})
}
})
editor.on('PreProcess', (e) => {
removeEmptyNodes(e.node)
})
}
})
}
Expand Down Expand Up @@ -303,3 +306,17 @@ function loadTinyMCEAsNeeded () {
})
return _loadPromise
}

function removeEmptyNodes (node) {
if (!node.getAttribute('ctzn-elem')) {
const inner = (node.innerHTML || '').trim()
if (!inner || inner === ' ') {
node.remove()
}
}

const children = Array.from(node.children)
for (let child of children) {
removeEmptyNodes(child, node.tagName + ' > ')
}
}

0 comments on commit b0496e8

Please sign in to comment.