| import { Node, mergeAttributes } from "@tiptap/core"; |
| import { ReactNodeViewRenderer } from "@tiptap/react"; |
| import { FootnoteView } from "../FootnoteView"; |
|
|
| declare module "@tiptap/core" { |
| interface Commands<ReturnType> { |
| footnote: { |
| insertFootnote: (content: string) => ReturnType; |
| }; |
| } |
| } |
|
|
| export const Footnote = Node.create({ |
| name: "footnote", |
| group: "inline", |
| inline: true, |
| atom: true, |
|
|
| addAttributes() { |
| return { |
| content: { default: "" }, |
| }; |
| }, |
|
|
| parseHTML() { |
| return [{ tag: 'span[data-type="footnote"]' }]; |
| }, |
|
|
| renderHTML({ HTMLAttributes }) { |
| return [ |
| "span", |
| mergeAttributes(HTMLAttributes, { "data-type": "footnote" }), |
| ]; |
| }, |
|
|
| addCommands() { |
| return { |
| insertFootnote: |
| (content: string) => |
| ({ commands }) => { |
| return commands.insertContent({ |
| type: this.name, |
| attrs: { content }, |
| }); |
| }, |
| }; |
| }, |
|
|
| addNodeView() { |
| return ReactNodeViewRenderer(FootnoteView); |
| }, |
| }); |
|
|