webapp/src/utils/renderUploadedImage.ts

23 lines
513 B
TypeScript
Raw Normal View History

import { Editor } from '@tiptap/core'
2024-06-24 17:50:27 +00:00
export const renderUploadedImage = (editor: Editor, image: { url: string; originalFilename?: string }) => {
editor
.chain()
.focus()
.insertContent({
type: 'figure',
attrs: { 'data-type': 'image' },
content: [
{
type: 'image',
attrs: { src: image.url },
},
{
type: 'figcaption',
content: [{ type: 'text', text: image.originalFilename }],
},
],
})
.run()
}