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.map(json.content).map(value => rewriteContent({
      validMarks,
      validNodes,
      json: value,
    }))
  }

  if (!validNodes.has

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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
2 participants