Parse images and iframes from tiptap to string descriptions

This commit is contained in:
Ian Philips 2022-10-05 14:08:51 -06:00
parent 2596d54831
commit 4bbadeb27c

View File

@ -85,6 +85,15 @@ export function richTextToString(text?: JSONContent) {
dfs(newText, (current) => { dfs(newText, (current) => {
if (current.marks?.some((m) => m.type === TiptapSpoiler.name)) { if (current.marks?.some((m) => m.type === TiptapSpoiler.name)) {
current.text = '[spoiler]' current.text = '[spoiler]'
} else if (current.type === 'image') {
current.text = '[Image]'
// This is a hack, I've no idea how to change a tiptap extenstion's schema
current.type = 'text'
} else if (current.type === 'iframe') {
const src = current.attrs?.['src'] ? current.attrs['src'] : ''
current.text = '[Iframe]' + (src ? ` url:${src}` : '')
// This is a hack, I've no idea how to change a tiptap extenstion's schema
current.type = 'text'
} }
}) })
return generateText(newText, exhibitExts) return generateText(newText, exhibitExts)