Sometimes there might arise an issue whereThe problem is that if I add spaces into the editor, the Quill will generate empty paragraphs. So no content only empty paragraphs will be displayed.
Inorder to resolve this issue,following code can be used.
const isQuillEmpty = (value) => {
if (value.replace(/<(.|n)*?>/g, '').trim().length === 0 && !value.includes("<img")) {
return true;
}
return false;
};
The isQuillEmpty function is designed to determine if the content within a Quill editor is considered empty. It checks two conditions:
HTML Tags Removal: It uses a regular expression (/<(.*?)>/g) to remove all HTML tags from the value. The replace function is employed for this purpose.
Empty Content Check: It then trims the resulting string and checks if its length is zero, meaning that the content consists only of spaces or is entirely empty.
Image Tag Check: Additionally, it ensures that the content does not include an <img> tag, meaning that it’s not just an image.
Return Value: The function returns true if the content is determined to be empty based on the conditions, otherwise, it returns false.