Paragraph tool: validate nbsp and empty <p>-tags

This commit is contained in:
Petr Savchenko 2018-02-01 20:48:20 +03:00
parent b9776c9c97
commit 05d657cdc6

View file

@ -67,8 +67,25 @@ var paragraph = (function(paragraph_plugin) {
*/
paragraph_plugin.validate = function(output) {
if (output.text === '')
return;
let text = output.text;
text = text.replace('&nbsp;', ' ');
text = text.replace(/\s/g, ' ');
text = text.trim();
/**
* Check for empty <p>:
* <p> </p>
*/
let div = document.createElement('div');
div.innerHTML = text;
text = div.textContent.trim();
if (!text) {
return false;
}
return output;
};