import l from "escape-html";
import { Targets as g } from "../types.es.js";
import { isMaliciousLink as c } from "../utils.es.js";
import { isLeafNode as m } from "./isLeafNode.es.js";
const p = (o) => `@[${o.category}:${o.id}]`, u = (o) => `${o}
`, f = (o, t, s, i) => {
  const a = s && s.parentType === o.olList, n = s.children.length === 1 && m(s.children[0]);
  let e = "";
  for (let r = 0; i > r; r++)
    a ? e += "   " : e += "  ";
  return `${e}${a ? "1." : "-"} ${t}${n ? `
` : ""}`;
}, d = (o, t, s, i) => (i === t.codeBlock || s === t.codeBlock || (o = l(o)), o), C = (o, t, s, i, a, n) => {
  const e = o.nodeTypes;
  switch (a) {
    case e.heading[1]:
      return `# ${t}
`;
    case e.heading[2]:
      return `## ${t}
`;
    case e.heading[3]:
      return `### ${t}
`;
    case e.heading[4]:
      return `#### ${t}
`;
    case e.heading[5]:
      return `##### ${t}
`;
    case e.heading[6]:
      return `###### ${t}
`;
    case e.blockQuote:
      return `> ${t}`;
    case e.codeBlock:
      return `\`\`\`${s.language || ""}
${t}
\`\`\`
`;
    case e.link: {
      let r = s.url ?? "";
      r = c(r) ? "" : r;
      const $ = s.target ?? g.Blank;
      return `[${t}](${r}){:target="${$}"}`;
    }
    case e.image: {
      let r = s.link ?? "";
      return r = c(r) ? "" : r, `![${s.caption}](${r})`;
    }
    case e.ulList:
    case e.olList:
      return `
${t}
`;
    case e.listItem:
      return f(e, t, s, i);
    case e.listItemChild:
      return u(t);
    case e.paragraph:
      return `${t}

`;
    case e.thematicBreak:
      return `
---${t}

`;
    case e.mention:
      return p(s);
    default:
      return d(t, e, a, n);
  }
};
export {
  C as applyFormattingToBlockNode
};
//# sourceMappingURL=applyFormattingToBlockNode.es.js.map
