"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HeadingSpecs = exports.headingToMarkdown = void 0;
const tslib_1 = require("tslib");
const const_1 = require("./const.js");
const utils_1 = require("./utils.js");
tslib_1.__exportStar(require("./const.js"), exports);
var utils_2 = require("./utils.js");
Object.defineProperty(exports, "headingToMarkdown", { enumerable: true, get: function () { return utils_2.headingToMarkdown; } });
const DEFAULT_PLACEHOLDER = (node) => 'Heading ' + node.attrs[const_1.headingLevelAttr];
const HeadingSpecs = (builder, opts) => {
    builder.addNode(const_1.headingNodeName, () => ({
        spec: {
            attrs: { [const_1.headingLevelAttr]: { default: 1 }, [const_1.headingLineNumberAttr]: { default: null } },
            content: '(text | inline)*',
            group: 'block',
            defining: true,
            parseDOM: [
                { tag: 'h1', attrs: { [const_1.headingLevelAttr]: 1 } },
                { tag: 'h2', attrs: { [const_1.headingLevelAttr]: 2 } },
                { tag: 'h3', attrs: { [const_1.headingLevelAttr]: 3 } },
                { tag: 'h4', attrs: { [const_1.headingLevelAttr]: 4 } },
                { tag: 'h5', attrs: { [const_1.headingLevelAttr]: 5 } },
                { tag: 'h6', attrs: { [const_1.headingLevelAttr]: 6 } },
            ],
            toDOM(node) {
                const lineNumber = node.attrs[const_1.headingLineNumberAttr];
                return [
                    'h' + node.attrs[const_1.headingLevelAttr],
                    lineNumber === null ? {} : { [const_1.headingLineNumberAttr]: lineNumber },
                    0,
                ];
            },
            placeholder: {
                content: builder.context.get('placeholder')?.heading ??
                    opts.headingPlaceholder ??
                    DEFAULT_PLACEHOLDER,
                alwaysVisible: true,
            },
        },
        fromMd: {
            tokenSpec: {
                name: const_1.headingNodeName,
                type: 'block',
                getAttrs: (tok) => ({ [const_1.headingLevelAttr]: Number(tok.tag.slice(1)) }),
            },
        },
        toMd: (0, utils_1.headingToMarkdown)(),
    }));
};
exports.HeadingSpecs = HeadingSpecs;
//# sourceMappingURL=index.js.map
