Tiptap: Check if content is empty (empty html tags)

Created on 10 Jan 2020  路  2Comments  路  Source: ueberdosis/tiptap

As mentioned in title, empty content keeps empty html tags (p, h1, h2, ...), but through Placeholder extension class is added to content container when it's empty. Is there any method on Editor which can check for empty content which returns true/false or at least get content (there are only getHtml and getJSON methods mentioned in docs); based on this I could just update data to an empty string instead of empty html tags.
I can write custom method in my code which checks for content using getJSON result; I was wondering if there is already method for that, but it's missing from docs.

feature request

Most helpful comment

Thanks for the suggestion @kikky7! And thanks for sharing @tguelcan!

We added editor.isEmpty() to the upcoming tiptap v2 for that purpose. 馃檶

All 2 comments

My temporary workaround

      .....
      onUpdate: ({ getHTML, getJSON }) => {
        if (!('content' in getJSON().content[0])) {
          this.context.model = null
          return
        }
        this.context.model = getHTML()
      },

Thanks for the suggestion @kikky7! And thanks for sharing @tguelcan!

We added editor.isEmpty() to the upcoming tiptap v2 for that purpose. 馃檶

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Auxxxxlx picture Auxxxxlx  路  3Comments

bernhardh picture bernhardh  路  3Comments

nekooee picture nekooee  路  3Comments

santicros picture santicros  路  3Comments

leandromatos picture leandromatos  路  4Comments