import { encodeCharacterReference as u } from "../util/encode-character-reference.es.js";
import { formatHeadingAsSetext as g } from "../util/format-heading-as-setext.es.js";
function d(r, m, e, o) {
  const i = Math.max(Math.min(6, r.depth || 1), 1), c = e.createTracker(o);
  if (g(r, e)) {
    const s = e.enter("headingSetext"), x = e.enter("phrasing"), a = e.containerPhrasing(r, {
      ...c.current(),
      before: `
`,
      after: `
`
    });
    return x(), s(), a + `
` + (i === 1 ? "=" : "-").repeat(
      // The whole size…
      a.length - // Minus the position of the character after the last EOL (or
      // 0 if there is none)…
      (Math.max(a.lastIndexOf("\r"), a.lastIndexOf(`
`)) + 1)
    );
  }
  const t = "#".repeat(i), f = e.enter("headingAtx"), h = e.enter("phrasing");
  c.move(t + " ");
  let n = e.containerPhrasing(r, {
    before: "# ",
    after: `
`,
    ...c.current()
  });
  return /^[\t ]/.test(n) && (n = u(n.charCodeAt(0)) + n.slice(1)), n = n ? t + " " + n : t, e.options.closeAtx && (n += " " + t), h(), f(), n;
}
export {
  d as heading
};
//# sourceMappingURL=heading.es.js.map
