import { YfmHeadingAttr } from "../const.js";
export { hasParentHeading, headingRule } from "../../../markdown/Heading/utils.js";
export { headingType } from "../../../markdown/Heading/HeadingSpecs/index.js";
// const slug = require('slugify');
export const getNodeAttrs = (level) => (node) => ({
    [YfmHeadingAttr.Level]: level,
    [YfmHeadingAttr.Id]: node.getAttribute('id') || '',
    [YfmHeadingAttr.Folding]: getFoldingAttr(node),
});
function getFoldingAttr(node) {
    const value = node.getAttribute(`data-${YfmHeadingAttr.Folding}`);
    if (value === 'true')
        return true;
    if (value === 'false')
        return false;
    return null;
}
// export const slugify = (str: string) =>
//     // same config as in yfm-transform
//     // https://github.com/yandex-cloud/yfm-transform/blob/master/lib/plugins/anchors/index.js#L97-L100
//     slug(str, {
//         lower: true,
//         remove: /[*+~.()'"!:@]/g,
//     });
export const renderYfmHeadingMarkup = (state, node) => {
    const folding = node.attrs[YfmHeadingAttr.Folding];
    const level = node.attrs[YfmHeadingAttr.Level];
    state.write(state.repeat('#', level) + (typeof folding === 'boolean' ? '+' : '') + ' ');
};
export const renderYfmHeadingAttributes = (state, node) => {
    const anchor = node.attrs[YfmHeadingAttr.Id];
    if (anchor /*&& anchor !== node.firstChild?.textContent*/) {
        state.write(` {#${anchor}}`);
    }
};
//# sourceMappingURL=utils.js.map
