How to tell if the current text editor is empty?

Are there any built-in methods that can tell if the current document is empty, or to get all contents of the text editor as a string without the other json / dom content? I ask for validation purposes when submitting a form. I couldn’t seem to find any in the documentation.

Thank you!

It depends on how you define an empty document, the textContent, nodeSize and childCount property of doc node may do some help.

1 Like

maybe you can try this:

const fragment = DOMSerializer

let divPM = document.createElement('div')

return divPM.innerHTML
let cachedEmptyTopNode = cachedEmptyTopNode || state.doc.type.createAndFill()
let diff = cachedEmptyTopNode.content.findDiffStart(state.doc.content)
if (diff == null) {
  return {class: "ProseMirror-emptydoc"}