import { Node, mergeAttributes } from '@tiptap/core'
import { ReactNodeViewRenderer, NodeViewWrapper, ReactNodeViewProps } from '@tiptap/react'
interface HighlightTextAttributes {
type: string;
text: string;
color: string;
}
interface HighlightTextOptions {
type?: string;
text: string;
color: string;
}
export function HighlightText(props: ReactNodeViewProps) {
const { type, text: initialText, color } = props.node.attrs as HighlightTextAttributes
const isRoleName = type === 'role'
return (
{initialText}
)
}
export const HighlightTextExtension = Node.create({
name: 'highlightText',
group: 'inline',
inline: true,
atom: false,
addAttributes() {
return {
type: { default: null },
text: { default: '' },
color: { default: 'blue' },
};
},
parseHTML() {
return [{ tag: 'highlight-text' }];
},
renderHTML({ HTMLAttributes }) {
return ['highlight-text', mergeAttributes(HTMLAttributes)];
},
addNodeView() {
return ReactNodeViewRenderer(HighlightText);
},
});