From 2c2bc617888911141b99f6ece6f45dfe9b692906 Mon Sep 17 00:00:00 2001 From: Pico2x Date: Thu, 13 Oct 2022 16:56:35 +0100 Subject: [PATCH] Fix bug with parsing in abritrary react components --- common/util/parse.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/common/util/parse.ts b/common/util/parse.ts index 6500d6ef..102a9e90 100644 --- a/common/util/parse.ts +++ b/common/util/parse.ts @@ -1,4 +1,4 @@ -import { generateText, JSONContent } from '@tiptap/core' +import { generateText, JSONContent, Node } from '@tiptap/core' import { generateJSON } from '@tiptap/html' // Tiptap starter extensions import { Blockquote } from '@tiptap/extension-blockquote' @@ -52,6 +52,26 @@ export function parseMentions(data: JSONContent): string[] { return uniq(mentions) } +// TODO: this is a hack to get around the fact that tiptap doesn't have a +// way to add a node view without bundling in tsx +function skippableComponent(name: string): Node { + return Node.create({ + name, + + group: 'block', + + content: 'inline*', + + parseHTML() { + return [ + { + tag: 'grid-cards-component', + }, + ] + }, + }) +} + const stringParseExts = [ // StarterKit extensions Blockquote, @@ -79,6 +99,7 @@ const stringParseExts = [ renderText: ({ node }) => '[embed]' + node.attrs.src ? `(${node.attrs.src})` : '', }), + skippableComponent('gridCardsComponent'), TiptapTweet.extend({ renderText: () => '[tweet]' }), TiptapSpoiler.extend({ renderHTML: () => ['span', '[spoiler]', 0] }), ]