"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuoteLinkSpecs = exports.QuoteLinkAttr = exports.isQuoteLinkNode = exports.quoteLinkType = exports.quoteLinkNodeName = void 0;
const quote_link_extension_1 = require("@diplodoc/quote-link-extension");
const utils_1 = require("../../../../utils/index.js");
const moveLinkToQuoteAttributes_1 = require("./md/moveLinkToQuoteAttributes.js");
exports.quoteLinkNodeName = 'yfm_quote-link';
exports.quoteLinkType = (0, utils_1.nodeTypeFactory)(exports.quoteLinkNodeName);
const isQuoteLinkNode = (node) => node.type.name === exports.quoteLinkNodeName;
exports.isQuoteLinkNode = isQuoteLinkNode;
var QuoteLinkAttr;
(function (QuoteLinkAttr) {
    QuoteLinkAttr["Cite"] = "cite";
    QuoteLinkAttr["DataContent"] = "data-content";
})(QuoteLinkAttr || (exports.QuoteLinkAttr = QuoteLinkAttr = {}));
const QuoteLinkSpecs = (builder) => {
    builder
        .configureMd((md) => md
        .use((0, quote_link_extension_1.transform)({
        bundle: false,
    }))
        .use(moveLinkToQuoteAttributes_1.moveLinkToQuoteAttributes))
        .addNode(exports.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: exports.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);
            });
        },
    }));
};
exports.QuoteLinkSpecs = QuoteLinkSpecs;
//# sourceMappingURL=index.js.map
