Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

722 B
Raw Blame
import type { Editor } from '@tiptap/core'
import posthog from 'posthog-js'

import { useUploadFiles } from 'lib/hooks/useUploadFiles'
import { lemonToast } from 'lib/lemon-ui/LemonToast'

export function useMarkdownEditorImageUpload(editor: Editor | null): ReturnType<typeof useUploadFiles> {
    return useUploadFiles({
        onUpload: (url, fileName) => {
            editor?.chain().focus().setImage({ src: url, alt: fileName }).run()
            posthog.capture('markdown image uploaded', { name: fileName })
        },
        onError: (detail) => {
            posthog.capture('markdown image upload failed', { error: detail })
            lemonToast.error(`Error uploading image: ${detail}`)
        },
    })
}