webapp/src/utils/renderUploadedImage.ts
Ilya Y 2bb600c8c6
Universal Figure with caption (#361)
Figure with caption for images and embed
2024-01-16 12:13:23 +03:00

27 lines
585 B
TypeScript

import { Editor } from '@tiptap/core'
import { UploadedFile } from '../pages/types'
import { hideModal } from '../stores/ui'
export const renderUploadedImage = (editor: Editor, image: UploadedFile) => {
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()
hideModal()
}