"use strict";
//
// Utils for working with custom ids in heading tokens.
// Copied from https://github.com/diplodoc-platform/transform/blob/master/src/transform/plugins/anchors/custom-id.ts
// TODO [MAJOR]: import directly from '@diplodoc/transform' after bump it in peerDependencies.
//
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeCustomIds = exports.removeCustomId = exports.getCustomIds = exports.CUSTOM_ID_EXCEPTION = exports.CUSTOM_ID_REGEXP = void 0;
exports.CUSTOM_ID_REGEXP = /\[?{ ?#(\S+) ?}]?/g;
exports.CUSTOM_ID_EXCEPTION = '[{#T}]';
const getCustomIds = (content) => {
    const ids = [];
    content.replace(exports.CUSTOM_ID_REGEXP, (match, customId) => {
        if (match !== exports.CUSTOM_ID_EXCEPTION) {
            ids.push(customId);
        }
        return '';
    });
    return ids.length ? ids : null;
};
exports.getCustomIds = getCustomIds;
const removeCustomId = (content) => {
    if (exports.CUSTOM_ID_REGEXP.test(content)) {
        return content
            .replace(exports.CUSTOM_ID_REGEXP, (match) => {
            if (match === exports.CUSTOM_ID_EXCEPTION) {
                return match;
            }
            return '';
        })
            .trim();
    }
    return content;
};
exports.removeCustomId = removeCustomId;
const removeCustomIds = (token) => {
    token.content = (0, exports.removeCustomId)(token.content);
    token.children?.forEach((child) => {
        child.content = (0, exports.removeCustomId)(child.content);
    });
};
exports.removeCustomIds = removeCustomIds;
//# sourceMappingURL=custom-id.js.map
