"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractHeaderPlugin = void 0;
const parseHeader_1 = require("../../utils/parseHeader");
const slugify_1 = require("./slugify");
exports.extractHeaderPlugin = (md, include = ['h2', 'h3']) => {
    md.renderer.rules.heading_open = (tokens, i, options, env, self) => {
        const token = tokens[i];
        if (include.includes(token.tag)) {
            const title = tokens[i + 1].content;
            const idAttr = token.attrs.find(([name]) => name === 'id');
            const slug = idAttr && idAttr[1];
            const data = md.__data;
            const headers = data.headers || (data.headers = []);
            headers.push({
                level: parseInt(token.tag.slice(1), 10),
                title: parseHeader_1.deeplyParseHeader(title),
                slug: slug || slugify_1.slugify(title)
            });
        }
        return self.renderToken(tokens, i, options);
    };
};
//# sourceMappingURL=header.js.map