Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async walkNode(node: Parser.Node): Promise {
if (node.nodeType === Parser.NodeType.TEXT_NODE) {
// ignore \n between single nodes
if ((node as Parser.TextNode).text === "\n") {
return "";
}
return await this.escapeDiscord((node as Parser.TextNode).text);
} else if (node.nodeType === Parser.NodeType.ELEMENT_NODE) {
const nodeHtml = node as Parser.HTMLElement;
switch (nodeHtml.tagName) {
case "em":
case "i":
return `*${await this.walkChildNodes(nodeHtml)}*`;
case "strong":
case "b":
return `**${await this.walkChildNodes(nodeHtml)}**`;
case "u":
return `__${await this.walkChildNodes(nodeHtml)}__`;
await Util.AsyncForEach(node.childNodes, async (child) => {
if (types.length && (
child.nodeType === Parser.NodeType.TEXT_NODE
|| !types.includes((child as Parser.HTMLElement).tagName)
)) {
return;
}
replies.push(await this.walkNode(child));
});
return replies;