import { transform as quoteLink } from '@diplodoc/quote-link-extension';
import { nodeTypeFactory } from "../../../../utils/index.js";
import { moveLinkToQuoteAttributes } from "./md/moveLinkToQuoteAttributes.js";
export const quoteLinkNodeName = 'yfm_quote-link';
export const quoteLinkType = nodeTypeFactory(quoteLinkNodeName);
export const isQuoteLinkNode = (node) => node.type.name === quoteLinkNodeName;
export var QuoteLinkAttr;
(function (QuoteLinkAttr) {
    QuoteLinkAttr["Cite"] = "cite";
    QuoteLinkAttr["DataContent"] = "data-content";
})(QuoteLinkAttr || (QuoteLinkAttr = {}));
export const QuoteLinkSpecs = (builder) => {
    builder
        .configureMd((md) => md
        .use(quoteLink({
        bundle: false,
    }))
        .use(moveLinkToQuoteAttributes))
        .addNode(quoteLinkNodeName, () => ({
        spec: {
            attrs: {
                class: { default: 'yfm-quote-link' },
                [QuoteLinkAttr.Cite]: { default: '' },
                [QuoteLinkAttr.DataContent]: { default: '' },
            },
            content: 'block+',
            group: 'block',
            defining: true,
            parseDOM: [
                {
                    tag: '.yfm-quote-link',
                    getAttrs(dom) {
                        return {
                            [QuoteLinkAttr.Cite]: dom.getAttribute(QuoteLinkAttr.Cite),
                            [QuoteLinkAttr.DataContent]: dom.getAttribute(QuoteLinkAttr.DataContent),
                        };
                    },
                    priority: builder.Priority.VeryHigh,
                },
            ],
            toDOM(node) {
                return ['blockquote', node.attrs, 0];
            },
            selectable: true,
        },
        fromMd: {
            tokenSpec: {
                name: quoteLinkNodeName,
                type: 'block',
                getAttrs: (tok) => ({
                    [QuoteLinkAttr.Cite]: tok.attrGet('cite'),
                    [QuoteLinkAttr.DataContent]: tok.attrGet('data-content') || null,
                }),
            },
        },
        toMd: (state, node) => {
            state.wrapBlock('> ', null, node, () => {
                state.write(`[${node.attrs[QuoteLinkAttr.DataContent]}](${node.attrs[QuoteLinkAttr.Cite]}){data-quotelink=true}`);
                state.write('\n');
                state.write('\n');
                state.renderContent(node);
            });
        },
    }));
};
//# sourceMappingURL=index.js.map
