@telegraf/entity
Version:
Convert Telegram entities to HTML or Markdown
38 lines (37 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarkdownV2 = exports.HTML = void 0;
/** escapeHTML borrowed from https://github.com/feathers-studio/hyperactive/blob/bbd67beace6744c4b8b48637a96c2daed416ebde/hyper/util.ts */
exports.HTML = (() => {
const escapables = {
"<": "<",
">": ">",
"&": "&",
};
const toEscape = /<|>|&/g;
return s => s.replace(toEscape, r => escapables[r] || r);
})();
exports.MarkdownV2 = (() => {
const escapables = {
"_": "\\_",
"*": "\\*",
"[": "\\[",
"]": "\\]",
"(": "\\(",
")": "\\)",
"~": "\\~",
"`": "\\`",
">": "\\>",
"#": "\\#",
"+": "\\+",
"-": "\\-",
"=": "\\=",
"|": "\\|",
"{": "\\{",
"}": "\\}",
".": "\\.",
"!": "\\!",
};
const toEscape = new RegExp("[" + Object.values(escapables).join("") + "]", "g");
return s => s.replace(toEscape, r => escapables[r] || r);
})();