"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HeadingSpecs = exports.headingType = exports.headingLineNumberAttr = exports.headingLevelAttr = exports.headingNodeName = void 0;
const schema_1 = require("../../../../utils/schema.js");
exports.headingNodeName = 'heading';
exports.headingLevelAttr = 'level';
exports.headingLineNumberAttr = 'data-line';
exports.headingType = (0, schema_1.nodeTypeFactory)(exports.headingNodeName);
const DEFAULT_PLACEHOLDER = (node) => 'Heading ' + node.attrs[exports.headingLevelAttr];
const HeadingSpecs = (builder, opts) => {
    builder.addNode(exports.headingNodeName, () => ({
        spec: {
            attrs: { [exports.headingLevelAttr]: { default: 1 }, [exports.headingLineNumberAttr]: { default: null } },
            content: '(text | inline)*',
            group: 'block',
            defining: true,
            parseDOM: [
                { tag: 'h1', attrs: { [exports.headingLevelAttr]: 1 } },
                { tag: 'h2', attrs: { [exports.headingLevelAttr]: 2 } },
                { tag: 'h3', attrs: { [exports.headingLevelAttr]: 3 } },
                { tag: 'h4', attrs: { [exports.headingLevelAttr]: 4 } },
                { tag: 'h5', attrs: { [exports.headingLevelAttr]: 5 } },
                { tag: 'h6', attrs: { [exports.headingLevelAttr]: 6 } },
            ],
            toDOM(node) {
                const lineNumber = node.attrs[exports.headingLineNumberAttr];
                return [
                    'h' + node.attrs[exports.headingLevelAttr],
                    lineNumber === null ? {} : { [exports.headingLineNumberAttr]: lineNumber },
                    0,
                ];
            },
            placeholder: {
                content: builder.context.get('placeholder')?.heading ??
                    opts.headingPlaceholder ??
                    DEFAULT_PLACEHOLDER,
                alwaysVisible: true,
            },
        },
        fromMd: {
            tokenSpec: {
                name: exports.headingNodeName,
                type: 'block',
                getAttrs: (tok) => ({ [exports.headingLevelAttr]: Number(tok.tag.slice(1)) }),
            },
        },
        toMd: (state, node) => {
            state.write(state.repeat('#', node.attrs[exports.headingLevelAttr]) + ' ');
            state.renderInline(node);
            state.closeBlock(node);
        },
    }));
};
exports.HeadingSpecs = HeadingSpecs;
//# sourceMappingURL=index.js.map
