Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.3 KB
Raw Blame
import { Node } from '@tiptap/core';

declare module '@tiptap/core' {
    interface Commands<ReturnType> {
        liquidVariable: {
            insertLiquidVariable: (variable: string) => ReturnType;
        };
    }
}

export const LiquidVariable = Node.create({
    name: 'liquidVariable',

    group: 'inline',

    inline: true,

    atom: true,

    addAttributes() {
        return {
            variable: {
                default: null,
            },
        };
    },

    parseHTML() {
        return [
            {
                tag: 'span[data-liquid-variable]',
            },
        ];
    },

    renderHTML({ node }) {
        return [
            'span',
            {
                'data-liquid-variable': node.attrs.variable,
                style: 'background-color: #e8f4ff; color: #0066cc; padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 0.9em; white-space: nowrap;',
            },
            `{{ ${node.attrs.variable} }}`,
        ];
    },

    addCommands() {
        return {
            insertLiquidVariable: (variable: string) => ({ chain }) => {
                return chain()
                    .insertContent({
                        type: this.name,
                        attrs: { variable },
                    })
                    .run();
            },
        };
    },
});