/**
 * @returns {MarkedExtension} A Marked extension object.
 */
export function ufmjs() {
    return {
        extensions: [
            {
                name: 'ufmjs',
                level: 'inline',
                start: (src) => src.search(/(?<!\\)\$\{/),
                tokenizer: (src) => {
                    const pattern = /^\$\{((?:[^{}]|\{[^{}]*\})*)\}/;
                    const regex = new RegExp(pattern);
                    const match = src.match(regex);
                    if (match) {
                        const [raw, text] = match;
                        return {
                            type: 'ufmjs',
                            raw: raw,
                            tokens: [],
                            text: text.trim(),
                        };
                    }
                    return undefined;
                },
                renderer: (token) => {
                    return `<umb-ufm-js-expression>${token.text}</umb-ufm-js-expression>`;
                },
            },
        ],
    };
}
