tfrere's picture
tfrere HF Staff
chore: initial commit
561e6f0
Raw
History Blame Contribute Delete
1.04 kB
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);
},
});