const cleanContent = (content: string) => { // Clean string from empty paragraphs and leading/ending spaces return content.replace(/
</p>/g, ‘’).trim(); };
const editor = useEditor({ onUpdate({ editor }) {
const getHtml = editor.getHTML();
const cleanedContent = cleanContent(getHtml);
// extract title and content
const title = getHtml.match(/<h1>(.*?)<\/h1>/)?.[1] || '';
const content = cleanedContent.replace(/<h1>.*?<\/h1>/, '').trim();
if (title !== draftTitle) {
onTitleChange(title);
}
if (content !== draftContent) {
onContentChange(content);
}
},
});