var replacements = [
[/\*/g, "\\*"],
[/#/g, "\\#"],
[/##/g, "\\##"],
[/###/g, "\\###"],
[/\*\*/g, "\\**"],
[/~~/g, "~~"],
[/\n/g, "<br>"],
[/\[]/g, "\\[]"],
[/\[x]/g, "\\[x]"],
[/-/g, "\\-"],
[/\[/g, "\\["],
[/\]/g, "\\]"],
[/\`/g, "\\`"],
[/\`\`\`/g, "\\```"],
[/_/g, "\\_"],
];
const htmlToMarkdown = (html) => {
return replacements.reduce(function (html, replacement) {
return html.replace(replacement[0], replacement[1]);
}, html);
};
const { HTML } = input.config() ?? {};
if (!HTML) {
throw Error("HTML field not found");
}
output.set("escapedHtml", htmlToMarkdown(HTML));