webapp/src/components/Editor/renderUploadedImage.ts

23 lines
509 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',
2024-06-26 08:22:05 +00:00
attrs: { src: image.url }
},
{
type: 'figcaption',
2024-06-26 08:22:05 +00:00
content: [{ type: 'text', text: image.originalFilename }]
}
]
})
.run()
}