mirror of
https://github.com/codex-team/editor.js
synced 2024-05-14 04:17:23 +02:00
Paragraph tool: validate nbsp and empty <p>-tags
This commit is contained in:
parent
b9776c9c97
commit
05d657cdc6
|
@ -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(' ', ' ');
|
||||
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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue