'use strict';

const shared = require('@mdit-vue/shared');

const headersPlugin = (md, {
  level = [2, 3],
  shouldAllowNested = false,
  slugify = shared.slugify,
  format
} = {}) => {
  const render = md.renderer.render.bind(md.renderer);
  md.renderer.render = (tokens, options, env) => {
    env.headers = shared.resolveHeadersFromTokens(tokens, {
      level,
      shouldAllowHtml: false,
      shouldAllowNested,
      shouldEscapeText: false,
      slugify,
      format
    });
    return render(tokens, options, env);
  };
};

exports.headersPlugin = headersPlugin;
