Skip to content

Render JSON as HTML and escape unsupported extensions #5289

Discussion options

You must be logged in to vote

You can try something like this:

import { getSchema } from '@tiptap/core'

/**
 * Get the invalid content from the `JSONContent`.
 */
function rewriteContent({ json, validMarks, validNodes }) {
  if (json.marks && Array.isArray(json.marks)) {
    json.marks = json.marks.filter(mark => {
      const name = typeof mark === 'string' ? mark : mark.type

      if (validMarks.has(name)) {
        return true
      }

      // Just ignore any unknown marks
      return false
    })
  }

  if (json.content && Array.isArray(json.content)) {
    json.content = Object.values(json.content).map(value => rewriteContent({
      validMarks,
      validNodes,
      json: value,
    }))
  }

  if (!validNodes

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@SimonTernoir
Comment options

@nperez0111
Comment options

Answer selected by nperez0111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants