import { Node, nodeInputRule } from '@tiptap/core'; import { Plugin, PluginKey } from '@tiptap/pm/state'; export interface VideoOptions { HTMLAttributes: Record; } declare module '@tiptap/core' { interface Commands { video: { /** * Set a video node */ setVideo: (src: string) => ReturnType; /** * Toggle a video */ toggleVideo: (src: string) => ReturnType; /** * Remove a video */ removeVideo: () => ReturnType; }; } } const VIDEO_INPUT_REGEX = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/; export const Video = Node.create({ name: 'video', group: 'block', content: 'inline*', draggable: true, isolating: true, addOptions() { return { HTMLAttributes: {} }; }, addAttributes() { return { src: { default: null, parseHTML: (el) => (el as HTMLSpanElement).getAttribute('src'), renderHTML: (attrs) => ({ src: attrs.src }) } }; }, parseHTML() { return [ { tag: 'video', getAttrs: (el) => ({ src: (el as HTMLVideoElement).getAttribute('src') }) } ]; }, renderHTML({ HTMLAttributes }) { return [ 'video', { controls: 'true', style: 'width: fit-content;', ...HTMLAttributes }, ['source', HTMLAttributes] ]; }, addCommands() { return { setVideo: (src: string) => ({ commands }) => commands.insertContent( `