Skip to content

Can i know the content is edited? #5430

Closed Answered by nperez0111
chenxiaoleizi asked this question in Questions & Help
Discussion options

You must be logged in to vote

Yea that could do it.

You can also do the parsing before it goes into the editor (to see what the editor would create) and use that as the comparison point.

I've written this before:

import { createNodeFromContent, Editor } from '@tiptap/core'

export function tryParseToTiptapJSON(content: string, editor: Editor) {

  try {
    const nodeOrFragment = createNodeFromContent(content, editor.schema, {
      parseOptions: {
        preserveWhitespace: false,
      },
    })

    return nodeOrFragment
  } catch (e) {
    return null
  }
}

Call .toJSON() to get the JSON version if you don't want fragments or nodes

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@nperez0111
Comment options

@nperez0111
Comment options

@chenxiaoleizi
Comment options

@nperez0111
Comment options

Answer selected by chenxiaoleizi
@chenxiaoleizi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants